Skip to content

Docker Environment for Symfony's Apps: Nginx, PHP7.0-fpm and MySQL. With docker-sync

Notifications You must be signed in to change notification settings

nietzscheson/docksy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

It's inspired completly in docker-symfony.

Docker Symfony (PHP7-FPM - NGINX - MySQL - Docker-Sync)

Installation

  1. Install and setup docker-sync. See the Wiki

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

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

    $ docker-sync-stack start
  4. Update your system host file (add docksy.dev) // change VIRTUAL_HOST value in .env

    # 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\.]+') "docksy.dev" >> /etc/hosts

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

  5. Prepare Symfony app

    1. Update app/config/parameters.yml

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

      $ docker-compose exec php bash
      $ composer install
      # Symfony2 | Symfony 3
      $ [php app/console | bin/console] doctrine:database:create
      $ [php app/console | bin/console] doctrine:schema:update --force
      # Only if you have `doctrine/doctrine-fixtures-bundle` installed
      $ [php app/console | bin/console] doctrine:fixtures:load --no-interaction
  6. Enjoy :-)

Usage

Just run docker-compose up -d, then:

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:

  • mysql: 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,

This results in the following running containers:

$ docker-compose ps
           Name                          Command               State              Ports            
--------------------------------------------------------------------------------------------------
docksy_db_1                       entrypoint.sh mysqld          Up      0.0.0.0:3306->3306/tcp      
docksy_nginx_1                    nginx                         Up      443/tcp, 0.0.0.0:80->80/tcp
docksy_php_1                      php-fpm                       Up      0.0.0.0:9000->9000/tcp      
docksy-sync                       eugenmayer/unison             Up      500/tcp, 192.168.99.100:32768->5000/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/app/console cache:clear # Symfony2
$ docker-compose exec php php /var/www/symfony/bin/console cache:clear # Symfony3
# Same command by using alias
$ docker-compose exec php bash
$ php app/console | bin/console cache:clear | -e=prod

# 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"

# F***ing cache/logs folder
$ sudo chmod -R 777 app/cache app/logs # Symfony2
$ sudo chmod -R 777 var/cache var/logs var/sessions # Symfony3

# 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)

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:

Contributing

First of all, thank you for contributing ♥
If you find any typo/misconfiguration/... please send me a PR or open an issue. You can also ping me on twitter.
Also, while creating your Pull Request on GitHub, please write a description which gives the context and/or explains why you are creating it.

Bibliography

About

Docker Environment for Symfony's Apps: Nginx, PHP7.0-fpm and MySQL. With docker-sync

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages