This is a complete stack for running Symfony 4 (latest version: Flex) into Docker containers using docker-compose tool.
First, clone this repository:
$ git clone https://github.com/rkosinski/docker-symfony.git
Next, put your Symfony application into main directory and do not forget to add symfony.localhost
in your /etc/hosts
file.
Make sure you adjust database_host
in parameters.yml
to the database container alias "db"
Then, set installation file as executable:
$ chmod a+xr install.sh
And then run it:
$ ./install.sh your-project-name
Remember : to add symfony.localhost
to hosts
file in your system.
You are done, you can visit your Symfony application on the following URL: http://symfony.localhost:88
Important : after all you can remove install.sh
file.
Note : you can rebuild all Docker images by running:
$ docker-compose build
Here are the docker-compose
built images:
db
: This is the MySQL database container (can be changed to postgresql or whatever indocker-compose.yml
file),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,
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:3308->3306/tcp
dockersymfony_nginx_1 nginx Up 443/tcp, 0.0.0.0:88->80/tcp
dockersymfony_php_1 php-fpm7 -F Up 0.0.0.0:9000->9000/tcp
You can access Nginx and Symfony application logs in the following directories on your host machine:
docker/logs/nginx
docker/logs/symfony
To use xdebug change the line "docker.host:127.0.0.1"
in docker-compose.yml and replace 127.0.0.1 with your machine ip address.
If your IDE default port is not set to 5902 you should do that, too.
You can check your host machine address by typing ip addr show
in unix terminal.
You can enter container (and perform some actions) by running docker exec -it docker-symfony_php_1 /bin/bash
in unix terminal command.
You are free to use the code in this repository under the terms of the 0-clause BSD license. LICENSE contains a copy of this license.