How to integrate Docker into a Symfony-based project

Description of the steps to follow to dockerize a Symfony project that uses Nginx, PHP-FPM and MySQL

Folder structure

📦symfony-docker
┣ 📂build
┣ 📂mysql
┣ 📂symfony
┗ 📜docker-compose.yml

Configuring the container for Nginx

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
docker-compose up -d --build

Configuring the container for PHP

Image for post
Image for post
Image for post
Image for post
docker-compose up -d --build

Configuring the container for MySQL

Image for post
Image for post

Authentication Plugin

Database Users

Image for post
Image for post

Dependencies between containers

Deploy the 3 containers

docker-compose up -d --build
symfony-docker_nginx_1 is up-to-datesymfony-docker_php_1 is up-to-dateCreating symfony-docker_mysql_1 ... done

Installing Symfony

docker exec -it  symfony-docker_php_1 bash
curl -sS https://get.symfony.com/cli/installer | bashmv /root/.symfony/bin/symfony /usr/local/bin/symfonysymfony new symfony --dir=/var/www/symfony
*** Please tell me who you are.Rungit config --global user.email "you@example.com"git config --global user.name "Your Name"to set your account's default identity
Image for post
Image for post
composer require symfony/orm-pack
composer require --dev symfony/maker-bundle
DATABASE_URL: mysql://symfony_user:symfony_password@mysql:3306/symfony_db?serverVersion=5.7
DATABASE_URL: mysql://symfony_user:symfony_password@database:3306/symfony_db?serverVersion=5.7
docker-compose up -d php
bin/console doctrine:database:create

Final thoughts

Do you want to read more articles like this?

Written by

Entre paseo y paseo con Simba desarrollo en Symfony y React

Get the Medium app