This is an example how to configure Symfony with Docker with an small app running adding comment and replies to the comments.
This example requires that you have nginx or somthing similar to run it in you localhost. However, you can use this repository that already has the nginx configured nginx-proxy.
- Docker
- docker-compose
- If you want to run it with
nginx-proxyjust download or clone the project and run the container.$ cd docker-nginx-proxy/ $ docker-compose up -d - Clone Symfony docker Example and build it with docker-compose
$ cd symfonyWithDocker/ $ docker-compose build && docker-compose up -d - Create an
.envfile in yourcode/.envdirectory with the following variables, it is up to you if you change the config.VIRTUAL_HOST=comments.docker DATABASE_URL=comments-db MYSQL_HOST=comments-db MYSQL_USER=admin MYSQL_PASSWORD=123456 MYSQL_DATABASE=symfony MYSQL_ROOT_PASSWORD=123456 - Connect into the container and run
composer, the following command will install the vendors.$ docker exec -it comments bash $ composer install # Now you will need to run `Doctrine` to migrate the database $ php bin/console doctrine:migrations:migrate - Add the virtual host into you
/etc/hostsfile127.0.0.1 comments.docker - Now open your browser and go to comments.docker
- Perhaps you are going to have a problem with permissions and this is because the container is running with super user and it create the folder
docker/local/mysql, so please change the permission of this folder if you have any problem and that will work fine again.
You can start listing and creating new submissions in the home page or list all replies of the main comment.
This code is pretty simple and you can follow through. However, it follows the basic principals of Symfony.
code/src/EntityThis folder has two entities one with comments and the other with responses both with theassertvalidation and the relationship between commentsOneToManywith responsescode/src/RepositoryHere you can create your custom queries or overwrite the existing ones.code/src/ControllerHere is where the main logic of you code should be.
For more information about Symfony check its official documentation.