Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

mjherraiz/docker-symfony-4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Symfony 4 (PHP7-FPM - NGINX - MySQL - ELK)

Docker-symfony gives you everything you need for developing Symfony 4 application. This complete stack run with docker and docker-compose (1.7 or higher).

Installation

  1. Create a .env from the .env.dist file. Adapt it according to your symfony application

    cp .env.dist .env
  2. Build/run containers with (with and without detached mode)

    $ docker-compose build
    $ docker-compose up -d
  3. Update your system host file (add symfony.localhost) Remember that server name is define in .env file in this demo I use symfony.localhost please replace with your custom server name if you decide to use another one

    # UNIX only: get containers IP address and update host (replace IP according to your configuration) (on Windows, edit C:\Windows\System32\drivers\etc\hosts)
    $ sudo echo $(docker network inspect bridge | grep Gateway | grep -o -E '[0-9\.]+') "symfony.localhost" >> /etc/hosts

    Note: For OS X, please take a look here and for Windows read this (4th step).

  4. Prepare Symfony app

    1. Update app/config/parameters.yml

      # path/to/your/symfony-project/app/config/parameters.yml
      parameters:
          database_host: db
    2. Composer install & create database

      $ docker-compose exec php bash
      $ composer install
      $ sf doctrine:database:create
      $ sf doctrine:schema:update --force
      # Only if you have `doctrine/doctrine-fixtures-bundle` installed
      $ sf doctrine:fixtures:load --no-interaction
  5. Enjoy :-)

Usage

Just run docker-compose up -d, then:

  • Symfony app: visit symfony.localhost
  • Symfony dev mode: set APP_ENV=dev and rebuild
  • Symfony test mode: set APP_ENV=test and rebuild
  • Symfony prod mode: set APP_ENV=prod and rebuild
  • Logs (Kibana): symfony.localhost:81
  • Logs (files location): logs/nginx and logs/symfony
  • Mailcatcher: visit symfony.localhost:1080

Customize

If you want to add optionnals containers like Redis, PHPMyAdmin... take a look on doc/custom.md.

How it works?

Have a look at the docker-compose.yml file, here are the docker-compose built images:

  • db: This is the MySQL database container,
  • php: This is the PHP-FPM container in which the application volume is mounted,
  • nginx: This is the Nginx webserver container in which application volume is mounted too,
  • elk: This is a ELK stack container which uses Logstash to collect logs, send them into Elasticsearch and visualize them with Kibana.
  • mailcatcher: This is a Mailcatcher container for email testing.

This results in the following running containers:

$ docker-compose ps
           Name                          Command               State              Ports            
--------------------------------------------------------------------------------------------------
dockersymfony_db_1            /entrypoint.sh mysqld            Up      0.0.0.0:3306->3306/tcp      
dockersymfony_elk_1           /usr/bin/supervisord -n -c ...   Up      0.0.0.0:81->80/tcp          
dockersymfony_nginx_1         nginx                            Up      443/tcp, 0.0.0.0:80->80/tcp
dockersymfony_php_1           php-fpm                          Up      0.0.0.0:9000->9000/tcp
dockersymfony_mailcatcher_1   /run.sh                          Up      0.0.0.0:1025->1025/tcp, 0.0.0.0:1080->1080/tcp   
      

Useful commands

# bash commands
$ docker-compose exec php bash

# Composer (e.g. composer update)
$ docker-compose exec php composer update

# SF commands (Tips: there is an alias inside php container)
$ docker-compose exec php php /var/www/symfony/bin/console cache:clear 
# Same command by using alias
$ docker-compose exec php bash
$ sf cache:clear

# Retrieve an IP Address (here for the nginx container)
$ docker inspect --format '{{ .NetworkSettings.Networks.dockersymfony_default.IPAddress }}' $(docker ps -f name=nginx -q)
$ docker inspect $(docker ps -f name=nginx -q) | grep IPAddress

# MySQL commands
$ docker-compose exec db mysql -uroot -p"root"

# Check CPU consumption
$ docker stats $(docker inspect -f "{{ .Name }}" $(docker ps -q))

# Delete all containers
$ docker rm $(docker ps -aq)

# Delete all images
$ docker rmi $(docker images -q)

Debug your app

  • How to config Xdebug? Xdebug is configured out of the box! Just config your IDE to connect port 9001 and id key PHPSTORM

Credits

This project at init was forked from Maxence Poutord work

About

🐳 A docker multicontainer with NGINX, PHP7-FPM, MySQL and ELK (Elasticsearch Logstash and Kibana) for developing symfony 4 apps

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published