Skip to content

arossokha/docker-for-symfony-lite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker stack for Symfony projects

For a more complete version visit: Docker-for-Symfony

Build Status :octocat: license contributions HitCount

Basic info

Previous requirements

This stack needs docker and docker-compose to be installed.

Installation

  1. Create a .env file from .env.dist and adapt it according to the needs of the application

    $ cp .env.dist .env && nano .env
  2. Build/run containers in detached mode (stop any local nginx/apache/mysql service)

    $ docker-compose build
    $ docker-compose up -d
  3. Get the bridge IP address

    $ docker network inspect bridge | grep Gateway | grep -o -E '[0-9\.]+'
    # OR an alternative command
    $ ifconfig docker0 | awk '/inet:/{ print substr($2,6); exit }'
  4. Update your system's hosts file with the IP retrieved in step 3.

    $ sudo nano /etc/hosts
  5. Prepare the Symfony application

    1. Update Symfony parameters (.env file)

      #...
      DATABASE_URL=mysql://user:userpass@mysql:3306/mydb
      #...
      
    2. Composer install & update the schema from the container

      $ docker-compose exec php bash
      $ composer install
      $ symfony doctrine:schema:update --force
  6. (Optional) Xdebug: Configure your IDE to connect to port 9001 with key PHPSTORM

How does it work?

We have the following docker-compose built images:

  • nginx: The Nginx webserver container in which the application volume is mounted.
  • php: The PHP-FPM container in which the application volume is mounted too.
  • mysql: The MySQL database container.
  • phpmyadmin: The PHPMyAdmin server/administration container.

Running docker-compose ps should result in the following running containers:

           Name                          Command               State              Ports
--------------------------------------------------------------------------------------------------
container_mysql         /entrypoint.sh mysqld            Up      0.0.0.0:3306->3306/tcp
container_nginx         nginx                            Up      443/tcp, 0.0.0.0:80->80/tcp
container_phpfpm        php-fpm                          Up      0.0.0.0:9000->9000/tcp
container_phpmyadmin    /run.sh phpmyadmin               Up      0.0.0.0:8080->80/tcp

Usage

Once all the containers are up, our services are available at:

  • Symfony app: http://symfony.dev:80
  • MySQL server: symfony.dev:3306
  • PHPMyAdmin: http://symfony.dev:8080
  • Log files location: logs/nginx and logs/symfony

🎉 Now we can stop our stack with docker-compose down and start it again with docker-compose up -d.

About

🐳 Docker stack for Symfony with: NGINX / PHP7-FPM / MySQL / PHPMyAdmin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published