Public Repository

Last pushed: 21 hours ago
Short Description
Meta-image to build Symfony projects using ONBUILD commands
Full Description

Symfony 3.* Docker meta-image

Introduction

This docker meta-image allows you to automatically produce development and production builds for PHP-FPM containers of your Symfony 3.*
projects through simple Dockerfile inheritance

Usage inside your application repositories

Dockerfile

Your application should have a Dockerfile that looks like this:

FROM movingimage/symfony:latest
MAINTAINER Your Name <your.name@movingimage.com>

Directory Structure

Your Symfony application's project needs to be structured as follows:

app/
bin/
src/
tests/
var/
web/
web/app.php
web/app_dev.php
.dockerignore
.gitignore
composer.json
composer.lock
Dockerfile

.env file

Instead of mounting environment variables on the Docker host through -e parameters, it's better
to generate a .env file containing all of the environment parameters. For example:

If you previously had in your app/config/parameters.yml.dist:

# ...
vmpro_username: ~
vmpro_password: ~
# ...

And in your composer.json:

# ...
   "extra": {
        # ...
        "incenteev-parameters": {
            "file": "app/config/parameters.yml",
            "env-map": {
                # ...

                "vmpro_username": "VMPRO__API__USERNAME",
                "vmpro_password": "VMPRO__API__PASSWORD",

                # ...
            }
        },
# ...

Previously it would build the static values into your app/config/paramters.yml. But there's a better way.

Create a file called .env in the root of your project that contains this:

VMPRO_USERNAME=my.user@movingimage.com
VMPRO_PASSWORD=MyPassword123

Then inside of your parameters.yml.dist:

# ...
vmpro_username: '%env(VMPRO_USERNAME)%'
vmpro_password: '%env(VMPRO_PASSWORD)%'
# ...

It will no longer statically render the values from your envvars into app/config/parameters.yml, instead it will only
require you to either provide a .env or define them as run-time container environment variables.

Building for development

To build your application for local development, you can just create a docker-compose.yml file that looks like this:

version: '2'
services:
  # ...

  portal-php:
      build: .
      container_name: portal-php-example
      volumes:
        - .:/usr/app

Then run the following to build and provision for local development:

$ docker-compose up

Building for QA:

To build with SYMFONY_ENV=dev and debugger enabled:

$ docker build . -t my-app:develop

Building for production

To build with SYMFONY_ENV=prod and debugger disabled:

$ docker build . -t my-app:develop --build-arg SYMFONY_ENV=prod

Changing the meta-image & pushing new versions

After you've changed the Dockerfile in this very source code repository, run the following
command to build a new version:

$ docker build . -t movingimage/symfony:latest

To push it to the Docker Hub repository:

$ docker push movingimage/symfony:latest
Docker Pull Command
Owner
movingimage

Comments (0)