An easy way to set up your Symfony application using Docker and docker-compose.
This will set up a development environment with nginx, php7.4-fpm, and mysql.
- Structure
- Setting the ENV file for docker-compose
- Docker-compose configuration model
- Quickstart for linux
- Quickstart for Windows
- Use docker commands
- Self-signed certificate on Nginx
- Configure nginx with SSL certificates "CertBot"
- Contributing
+---docker
| | .env
| | .env.dist
| | .gitignore
| | docker-compose.yml
| | run.sh
| |
| \---services
| +---mysql
| | Dockerfile
| |
| +---nginx
| | | .dockerignore
| | | .gitignore
| | | app.conf
| | | Dockerfile
| | | nginx.conf
| | |
| | \---logs
| | access.log
| | error.log
| |
| \---php
| Dockerfile
| php.ini
| www.conf
|
\---images
\---web
\---bin
\---config
\---public
\---src
\---var
\---vendor
| | .env
| | .env.dist
| | .gitignore
| | composer.json
| | composer.lock
| | symfony.lock
It includes the following:
APP_PATH=../web
WORKING_DIR=/code
PROJECT_NAME=project
VIRTUAL_HOST=localhost #for example you can use: project.local
APP_ENV=dev
MYSQL_DATABASE=db_project
MYSQL_USER=user
MYSQL_PASSWORD=password
MYSQL_ROOT_PASSWORD=root
It includes the following:
- NGINX
- port 80 (default)
- port 443 for SSL connection (default)
- use depends_on "php" #Express dependency between services
- PHP
- FPM configured for NGINX
- MySQL
- port 3306 (default)
Need install:
- docker 18.06.0+
- docker-compose 1.18.0+
- Create the docker group if it does not exist
sudo groupadd docker
- Add your user to the docker group
sudo usermod -aG docker $USER
- Need to reboot your computer
sudo reboot
If you WANT to use yourself host name, you MUST run:
echo "127.0.0.1 project.local" >> /etc/hosts
Create new .env file, copy content from .env.dist [.env for docker-compose]
- cd /YOUR_PROJECT_DIRECTORY/docker
cp .env.dist .env
Create new .env file, copy content from .env.dist [.env for symfony]
- cd /YOUR_PROJECT_DIRECTORY/web
cp .env.dist .env
Open Git Bash in /YOUR_PROJECT_DIRECTORY/docker:
sudo chmod +x run.sh
./run.sh
Next step:
docker exec -it project_php composer install
Service | Path |
---|---|
Website | http:https://localhost |
Need install:
If you WANT to use yourself host name, you MUST do it:
- PowerShell run as administrator
echo "127.0.0.1 project.local" >> C:\Windows\System32\Drivers\etc\hosts
Create new .env file, copy content from .env.dist [.env for docker-compose]
- cd /YOUR_PROJECT_DIRECTORY/docker
cp .env.dist .env
Create new .env file, copy content from .env.dist [.env for symfony]
- cd /YOUR_PROJECT_DIRECTORY/web
cp .env.dist .env
Open Git Bash in /YOUR_PROJECT_DIRECTORY/docker:
./run.sh
Next step:
winpty docker exec -it project_php composer install
Service | Path |
---|---|
Website | http:https://localhost |
docker images #List images
docker ps #List containers
docker exec -it project_php bash #Run a command in a running container
docker stop $(docker ps -aq) #Stop one or more running containers
docker rmi -f $(docker images -q) #Remove all images at once
docker history #Show the history of an image
docker logs #Fetch the logs of a container
Use this to delete everything: docker system prune -a --volumes
More info -> The base command for the Docker CLI.
docker exec -it project_nginx bash
openssl genrsa -des3 -out server.key 2048
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
cp server.crt /etc/nginx/
cp server.key /etc/nginx/
vim /etc/nginx/nginx.conf
server {
listen 443 ssl;
ssl_certificate /etc/nginx/server.crt;
ssl_certificate_key /etc/nginx/server.key;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
And last step: nginx -s reload
Service | Path |
---|---|
Website | https://localhost |
docker exec -it project_nginx bash
- Install CertBot
apt-get install certbot python-certbot-nginx
- Either get and install your certificates...
sudo certbot --nginx
nginx -s reload
More info -> Certbot instructions nginx on Debian 10
First of all, thank you for contributing If you find any typo or misconfiguration. please send me a PR or open an issue. You can also ping me on LinkedIn