Using docker with Symfony

Hi fellas, in this post I’d like to share an example how I use docker with Symfony. Docker is good tool for web developers, and there are a lot of articles about it, but how it should be used with symfony (or other framework)? I’m going to show it below:

First we need to install docker, and docker-compose (for easier containers management). You can read more about docker technology on their official website.

Create docker folder to store php / nginx settings and logs. Also I was needed custom php extensions that’s why I created php-fpm folder with Dockerfile.

Create docker-compose.yml file in your project root directory

elasticsearch:
  image: elasticsearch:latest
  command: elasticsearch -Des.network.host=0.0.0.0
  ports:
    - "9200:9200"
    - "9300:9300"

mysql:
  image: mariadb
  ports:
    - "3306:3306"
  environment:
      MYSQL_ROOT_PASSWORD: admin

phpfpm:
  image: shar/php71
  ports:
    - "9000:9000"
  volumes:
    - ./:/usr/share/nginx/html
    - ./docker/config/php.ini:/usr/local/etc/php/php.ini
  links:
    - mysql
    - elasticsearch

nginx:
  image: tutum/nginx
  ports:
    - "80:80"
  links:
    - phpfpm
  volumes_from:
    - phpfpm
  volumes:
    - ./docker/config/default.conf:/etc/nginx/sites-available/default
    - ./docker/config/default.conf:/etc/nginx/sites-enabled/default
    - ./docker/logs/nginx-error.log:/var/log/nginx/error.log
    - ./docker/logs/nginx-access.log:/var/log/nginx/access.log

At the end build your image if you need and run in terminal “docker-compose up -d”, it will create containers and loads it.

You can find full example of using docker with symfony:
https://github.com/emptyhand/symfony-boilerplate

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.