Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Latest commit

 

History

History
152 lines (112 loc) · 5.85 KB

compose.md

File metadata and controls

152 lines (112 loc) · 5.85 KB

Symfony development with docker-compose

IMPORTANT - These images do not contain Symfony. They are intended to be used with an already existing (or new) Symfony project on your host machine, that will be mounted as a data volume.

Even if the instructions that follow are very "Symfony oriented", the compose file examples can be used as they are for almost any PHP application.

A compose file example is provided. It makes use of akeneo/fpm and nginx. We explain how to use it below.

Using the images

Just copy the FPM compose file to the root of your project (don't forget to rename it docker-compose.yml).

The application is mounted into a data volume by the compose file, as follow:

services:
  fpm:
    image: akeneo/fpm
    user: docker
    volumes:
      - ./:/srv/application

  nginx:
    image: nginx
    volumes:
      - ./:/srv/application:ro

Read only access is enough for nginx, only FPM needs a full access on the application.

Important: As the application is shared between your host and the FPM container, it is mandatory on Linux that your user ID and group ID are 1000, as it is for the docker user inside the container. Without that, you'll end up with a permission mess that will prevent your application from running. This is not a problem on Windows and Mac OX as both are using a virtual machine to run Docker, with user and group IDs 1000.

By default, latest version of akeneo/fpm is used in the compose file. But you can also choose to use a specific tag. Look here to know all available tags.

Run and stop the containers

All docker-compose commands are to be ran from the folder containing the compose file.

To start your containers, just run:

$ docker-compose up -d

To stop the containers, run:

$ docker-compose stop

but if you want to completely remove everything (containers, networks and volumes), then run:

$ docker-compose down -v

This, of course, will not delete the application you cloned on your machine, only the Docker containers.

Install and run Symfony

Configure Symfony

First, make sure that the database settings are as the containers expect them:

# /host/path/to/you/pim/app/config/parameters.yml
parameters:
    database_driver: pdo_mysql
    database_host: mysql
    database_port: null
    database_name: symfony
    database_user: symfony
    database_password: symfony
    locale: en
    secret: ThisTokenIsNotSoSecretChangeIt

Configure nginx

akeneo/fpm image contains only PHP-FPM. So to be able to access your application in a web browser, you need to associate the FPM container with a nginx one (you could use Apache with mod FCGI too).

You can use the official nginx image available on Docker Hub. The FPM compose file already defines the appropriate service. You just need to copy the nginx server configuration to the appropriate folder. The compose file expects it in a docker subfolder of your project, but it is up to you to choose another folder.

Optionally, you can also add a configuration file to set the maximum size of uploaded files (the nginx service of the compose file is already set for it).

Install Symfony

You can install vendors (if needed) by running:

$ docker-compose exec fpm composer update

You should now be able to access your application from your host through http://localhost:8080/ (of course, you can change the host port in the compose file).

Advanced configuration

Composer

You can set the composer home with the following environment variable:

services:
  fpm:
    environment:
      COMPOSER_HOME: '/home/docker/.composer'`

This will ensure where composer keeps its data inside the container, and allow you to safely map your own composer home folder, sharing both your configuration (including your GitHub token, which is mandatory to install Akeneo PIM standard and/or enterprise edition) and your composer cache (and so reducing considerably the dependencies installation time):

services:
  fpm:
    volumes:
      - ~/.composer:/home/docker/.composer

Beware that on recent Linux system, composer cache and configuration are usually separated in .cache/composer and .config/composer. You then need to adapt the environment variables of your compose file as follow:

services:
  fpm:
    environment:
      COMPOSER_CACHE_DIR: '/home/docker/.cache/composer'
      COMPOSER_HOME: '/home/docker/.config/composer'
    volumes:
      - ~/.cache/composer:/home/docker/.cache/composer
      - ~/.config/composer:/home/docker/.config/composer

Xdebug

Xdebug is deactivated by default. If you want to activate it, you need to set the following environment variables:

services:
  fpm:
    environment:
      PHP_XDEBUG_ENABLED: 1
      XDEBUG_CONFIG: 'client_host=<your host IP address>'

Then you just have to run docker-compose up -d again and XDebug will be activated.

Also, you can configure a few more parameters through environment variables (all optional).

  • PHP_XDEBUG_IDE_KEY: the IDE KEY you want to use (by default XDEBUG_IDE_KEY)
  • PHP_XDEBUG_REMOTE_HOST: your host IP address (again), this one is needed only if the docker daemon run on TCP instead of unix domain socket (on Mac OS for instance)