https://docs.docker.com/compose/install/
The most interesting folders:
- ./images The folder with custom Docker Images.
- ./local Folder for local changes. It can be convenient to use it together with the docker-compose.local.yml file.
- ./mounted A folder for exchanging files between the PC and the Docker container.
- ./volumes The folder with Docker Volumes in Linux structure.
- ./volumes/etc/nginx/conf.d Nginx configuration files for projects.
- ./volumes/etc/ssl SSL certificates for projects.
- ./volumes/var/log Logs from different services.
- ./volumes/var/www Nginx projects.
- Copy the ./.env.sample file to the ./.env. Check it and edit some parameters if needed.
- Copy the ./volumes/root/bash_history/mysql.sample file to the ./volumes/root/bash_history/mysql for saving command history in the MySQL container.
- Copy the ./volumes/root/bash_history/node.sample file to the ./volumes/root/bash_history/node for saving command history in the Node container.
- Copy the ./volumes/root/bash_history/php.sample file to the ./volumes/root/bash_history/php for saving command history in the PHP containers.
- Optional. Copy the ./volumes/root/.blackfire.ini.sample file to the ./volumes/root/.blackfire.ini for configuration Blackfire if you have plans to use it.
- Optional. Copy the ./docker-compose.local.yml.sample file to the ./docker-compose.local.yml and edit it, if you need some changes in the Docker configurations locally.
- Optional. If your want to have local domains for PhpMyAdmin, RabbitMQ, and MailCatcher, you need to add the data to you local /etc/hosts file, like:
127.0.0.1 pma.loc 127.0.0.1 rabbitmq.loc 127.0.0.1 mailcatcher.loc
Docker Build
docker-compose build
Docker Up
docker-compose up -d
Docker Stop
docker-compose stop
If you use some changes for the local environment you need to mention it in all docker-compose commands, like:
docker-compose -f docker-compose.yml -f docker-compose.local.yml build
- Copy the dir with the project to the ./volumes/var/www/project-name folder.
- Copy the database dump to the ./mounted folder.
- Go inside the MySQL container, create the database, and copy your dump to the database.
mysql -u root -p project_database < /home/mounted/project_dump.sql
- Generate an SSL certificate if you have plans to use Varnish or need it for other aims.
openssl req -newkey rsa:2048 -sha256 -keyout project_name.key -nodes -x509 -days 365 -out project_name.crt
- Common Name = project-domain.loc
- Move the certificates to the ./volumes/etc/ssl/certs and ./volumes/etc/ssl/private folders.
- Go to the ./volumes/etc/nginx/conf.d and create the Nginx configuration for the project.
In case you encounter the error 502 Bad Gateway (no resolver defined to resolve php82), define a DNS Resolver. Add the resolver directive to your NGINX configuration to specify which DNS server to use. For example:
#resolver 127.0.0.11 valid=30s; # Use Docker's internal DNS #resolver_timeout 5s; server { listen 80; server_name project-domain.loc www.project-domain.loc; set $MAGE_ROOT /var/www/project-name; set $FASTCGI_PASS "php82:9000"; access_log /var/log/nginx/project_name.access.log; error_log /var/log/nginx/project_name.error.log; include conf.d/samples/magento247.conf; } server { listen 443 ssl; http2 on; server_name project-domain.loc www.project-domain.loc; ssl_certificate /etc/ssl/docker/certs/project_name.crt; ssl_certificate_key /etc/ssl/docker/private/project_name.key; access_log /var/log/nginx/project_name.access.log; error_log /var/log/nginx/project_name.error.log; location / { proxy_pass http://varnish:6081; proxy_buffer_size 8k; proxy_busy_buffers_size 8k; proxy_buffers 1024 8k; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-Port 443; proxy_set_header Host $host; proxy_read_timeout 1200s; } }
127.0.0.11 is the default internal DNS server. You can verify DNS settings inside the NGINX container:resolver 127.0.0.11 valid=30s; # Use Docker's internal DNS resolver_timeout 5s;
cat /etc/resolv.conf
- Add the project host to your local /etc/hosts file.
127.0.0.1 project-domain.loc
- Add your own configurations to the project like connection to the DB, Redis, RabbitMQ, ElasticSearch, MailCatcher, build styles, etc.
- Optional. Add the configurations to the docker-compose.local.yml if you use it.
- Restart the Docker Compose or separate containers.
docker-compose stop && docker-compose up -d
Add Docker server (if it wasn't added yet)
- File -> Settings -> Build, Execution, Deployment -> Docker -> [+]
- Name: Docker
- Connect to Docker daemon with: Unix socket
Add external interpreter
- File -> Settings -> PHP
- PHP language level: 7.4
- CLI Interpreter: php74, or add new: [...]
- [+]
- From: Docker Compose
- Server: Docker
- Configurations file(s): /.../docker-default/docker-compose.yml
- Service: php74
- Lifecycle: Connect to existent container
- [+]
Add PHP server
- File -> Settings -> PHP -> Servers -> [+]
- Name: Docker
- Host: project-domain.loc
- Port: 80
- Debugger: Xdebug
- Use path mappings: yes
- Absolute path on the server:
- root = /var/www/project
- pub = /var/www/project/pub (if needed)
- Absolute path on the server:
Add run configuration
- Main menu -> Run -> Edit configurations
- [+] -> PHP Web Page
- Name: project-domain.loc
- Server: Docker
If debug doesn't work, makes sense to try the next two steps:
- Change xDebug host in PHP container settings.
;for PHP v7.4: xdebug.remote_host=192.168.220.1 ;for PHP v8.2 xdebug.client_host=192.168.220.1
- UFW, allow network if needed (in terminal):
sudo ufw allow in from 192.168.220.0/24 to any port 9000 comment xDebug9000
- Host: nginx
- Port: 80
- SSL: 443
- Folder with configs: ./volumes/etc/nginx/conf.d
- Folder with projects: ./volumes/var/www
- Folder with SSL certificates: ./volumes/etc/ssl
docker-compose exec nginx /bin/bash
- Host: varnish
- Port: 6081
docker-compose exec varnish /bin/bash
- Host: php74
- Port: 9000
docker-compose exec php74 /bin/bash
- Host: php82
- Port: 9000
docker-compose exec php82 /bin/bash
- Host: mysql
- Port: 3306
- User: {see .env file}
- Password: {see .env file}
- Folder for dumps: ./mounted (/home/mounted)
docker-compose exec mysql /bin/bash
If you see an error inside the container, like: mysql: [Warning] World-writable config file '/etc/mysql/conf.d/my.cnf' is ignored. You can try to change the permissions for the config file: chmod 644 /etc/mysql/conf.d/my.cnf.
- URL: http://localhost:8090/, http://pma.loc/
- Username: {see .env file}
- Password: {see .env file}
docker-compose exec phpmyadmin /bin/bash
- Host: elasticsearch7
- Port: 9200
docker-compose exec elasticsearch7 /bin/bash
- Host: redis
- Port: 6379
docker-compose exec redis /bin/bash
- Host: rabbitmq
- Port: 5672
- URL: http://localhost:15672/, http://rabbitmq.loc/
- Username: {see .env file}
- Password: {see .env file}
docker-compose exec rabbitmq /bin/bash
- Host: mailcatcher
- Port: 1025
- URL: http://localhost:1080/, http://mailcatcher.loc/
- Host: node18
docker-compose exec node18 /bin/bash