This is a complete stack for running Symfony 4 (latest version: Flex) into Docker containers using docker-compose tool.
Note: Docker must be already installed in your machine :)
-
Clone this repository:
$ git clone git@github.com:hounaida/docker-for-symfony.git
-
Put your Symfony application into
symfonyfolder and do not forget to addsymfony.localhostin your/etc/hostsfile.$ cd docker-for-symfony $ git clone https://github.com/hounaida/social_web_app.git -
Make sure you adjust
DATABASE_URLinsymfony/.envfile like the following:$ DATABASE_URL=mysql://root:symfony@db/symfony -
Build all docker images
$ docker-compose build
-
Run containers
$ docker-compose up -d
-
Install project dependencies
$ docker exec -it docker-for-symfony_php_1 /bin/sh $ composer install -
Create database schema & populate sample data
$ docker exec -it docker-for-symfony_php_1 /bin/sh $ php bin/console doctrine:schema:create $ bin/console doctrine:fixtures:load
You are done, you can visit your Symfony application on the following URL: http://symfony.localhost/.
You can also visit PhpMyAdmin via this URL: http://symfony.localhost:8080/
Here are the docker-compose built images:
db: This is the MySQL database container (can be changed to postgresql or whatever indocker-compose.ymlfile),php: This is the PHP-FPM container including the application volume mounted on,nginx: This is the Nginx webserver container in which php volumes are mounted too,phpmyadmin: This is the phpmyadmin container.
This results in the following running containers:
> $ docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------
dockersymfony_db_1 docker-entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp
dockersymfony_nginx_1 nginx Up 443/tcp, 0.0.0.0:80->80/tcp
dockersymfony_php_1 php-fpm7 -F Up 0.0.0.0:9000->9000/tcpdockersymfony_php_1
phpmyadmin/phpmyadmin /run.sh supervisord Up 9000/tcp, 0.0.0.0:8080->80/tcpYou can access Nginx and Symfony application logs in the following directories on your host machine:
logs/nginxlogs/symfony