Skip to content

A docker multicontainer with NGINX, PHP7-FPM, MySQL, Redis and ELK (Elasticsearch Logstash and Kibana)

Notifications You must be signed in to change notification settings

a-dasilva/docker-symfony

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Build Status

Credit: this is a kind of fork from eko/docker-symfony. Thanks to him :-)

Installation

  1. Retrieve git project

    $ git clone git@github.com:maxpou/docker-symfony.git
  2. Move your Symfony project into symfony folder

  3. Build containers with (with and without detached mode)

    $ docker-compose up
    $ docker-compose up -d
  4. Update your host file (add symfony.dev)

    # get containers IP address and update host (replace IP according to your configuration)
    $ docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -f name=nginx -q)
    $ sudo echo "171.17.0.1 symfony.dev" >> /etc/hosts
  5. Prepare Symfony app

    1. Retrieve DB&Redis IP

      $ docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -f name=db -q)
      $ docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -f name=redis -q)
    2. Update app/paraeters.yml (adapt hosts according to previous results)

      parameters:
          database_host: 172.17.0.4
          database_port: null
          database_name: symfony
          database_user: root
          database_password: root
          redis_host: 172.17.0.3
    3. Composer install

      $ docker exec -ti $(docker ps -f name=php -q) sh -c  "cd /var/www/symfony/ && composer install"
  6. Enjoy :-)

Using

How it works?

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

  • application: This is the Symfony application code container,
  • 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,
  • redis: This is a redis database container.

This results in the following running containers:

$ docker-compose ps
           Name                          Command               State              Ports            
--------------------------------------------------------------------------------------------------
dockersymfony_application_1   /bin/bash                        Up                                  
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_redis_1         /entrypoint.sh redis-server      Up      0.0.0.0:6379->6379/tcp      

Useful commands

# Composer (e.g. composer update)
$ docker exec -ti $(docker ps -f name=php -q) sh -c  "cd /var/www/symfony/ && composer update"

# SF commands
$ docker exec -ti $(docker ps -f name=php -q) php /var/www/symfony/app/console cache:clear

# bash commands
$ docker exec -ti $(docker ps -f name=php -q) /bin/bash

# MySQL commands
$ docker exec -ti $(docker ps -f name=db -q) mysql -uroot -p"root"

# Redis commands
$ docker exec -ti $(docker ps -f name=redis -q) sh -c 'exec redis-cli'

# F***ing cache/logs folder
$ sudo chmod -R 777 symfony/app/cache symfony/app/logs

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

# Delete all containers
$ docker rm $(docker ps -a -q)

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

FAQ

  • Got this error: ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running? If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable. ?
    Run docker-compose up -d instead.

  • Permission problem? See this doc (Setting up Permission)

TODO

  • Upgrade ELK stack. Install Timelion <3
  • MySQL -> PostgreSQL
  • Move SF app folder?
  • use php7-fpm/php.ini

About

A docker multicontainer with NGINX, PHP7-FPM, MySQL, Redis and ELK (Elasticsearch Logstash and Kibana)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Nginx 100.0%