Code Monkey home page Code Monkey logo

symfony-docker's Introduction

symfony-docker

Symfony + Nginx + php-fpm

Build Status

Docker for Symfony application, powered by Nginx and php-fpm.

Based on Debian Jessie.

If you are experiencing some issues, take a look at TROUBLESHOOTING

Supported tags and respective Dockerfile links

Image tags follows PHP versions

latest 8.1 (8.1/Dockerfile)

8.0 (8.0/Dockerfile)

7 7.4 (7.4/Dockerfile)

7.3 (7.3/Dockerfile)

7.2 (7.2/Dockerfile)

7.1 Not maintained, END OF LIFE

7.0 Not maintained, END OF LIFE

5, 5.6 Not maintained, END OF LIFE

5.4 Not maintained, END OF LIFE

Compatibility matrix

Symfony
Image 2.x 3.x 4.x 5.x 6.x
8.1 ✔️ (not tested) ✔️ (not tested) ✔️ (not tested)
8.0 ✔️ (not tested) ✔️ (default) ✔️ (not tested)
7.4 ✔️ ✔️ (default)
7.3 ✔️ (not tested) ✔️ (not tested) ✔️ (default) ✔️ (not tested)
7.2 ✔️ (not tested) ✔️ ✔️ ✔️ (not tested)
7.1 ✔️ (not tested) ✔️ ✔️
7.0 ✔️ (not tested) ✔️ (not tested)
5.6 ✔️ (not tested) ✔️ (not tested)

Composer versions :

  • 8.0+ : 2.x
  • 7.4 : 2.x
  • 7.3 : 1.10.17
  • 7.2 : 1.10.17

Usage

docker pull kibatic/symfony

Then run in your symfony folder

# Image >= 7.3 & Symfony 2.x, 3.x
docker run -e SYMFONY_VERSION=3 -v $(pwd):/var/www -p 8080:80 kibatic/symfony:7.3

# Image >= 7.3 & Symfony 4.x
docker run -v $(pwd):/var/www -p 8080:80 kibatic/symfony:7.3

# Image < 7.3 & Symfony 2.x, 3.x
docker run -v $(pwd):/var/www -p 8080:80 kibatic/symfony:7.2

# Image < 7.3 & Symfony 4.x
docker run -e SYMFONY_VERSION=4 -v $(pwd):/var/www -p 8080:80 kibatic/symfony:7.2

Symfony app will be accessible on http://localhost:8080/

Custom nginx configuration

If you want to replace the default nginx settings, overwrite configuration file at /etc/nginx/sites-enabled/default.

COPY nginx.conf /etc/nginx/sites-enabled/default

You may also want to add only some directives in existing site config.

COPY custom-config.conf /etc/nginx/conf.d/docker/custom-config.conf

Logging (PHP >= 7.3)

For both production and dev environment you should log to stdout / stderr, example below.

# config/packages/monolog.yaml
monolog:
    handlers:
        stdout:
            type: stream
            path: 'php://stdout'
            level: debug
            channels: ['!event']
            # (Optional) format logs to json
            #formatter: monolog.formatter.json
        stderr:
            type: stream
            path: 'php://stderr'
            level: error
            # (Optional) format logs to json
            #formatter: monolog.formatter.json

Logging (PHP < 7.3)

A common practice is to log to stdout, but there are major bug in php-fpm wich makes stdout logging not reliable :

This image setup a known workaround (see here) and expose a log stream as env var LOG_STREAM, but you cannot log to stdout For a proper logging you have to configure monolog to log to this stream

# app/config_dev.yml
monolog:
    handlers:
        main:
            type:   stream
            path:   '/tmp/stdout'
            level:  debug

You can also use symfony %env(LOG_STREAM)% if your symfony version is compatible with this syntax

We also provide a default dirty solution for standard monolog configuration, this is not recommended in production

tail -q -n 0 -F app/logs/dev.log app/logs/prod.log var/logs/dev.log var/logs/prod.log

Minimal package included

  • nginx
  • php*-fpm
  • php*-cli
  • php*-intl
  • php*-mbstring

Exposed port

  • 80 : nginx

symfony-docker's People

Contributors

eliecharra avatar elvisciotti avatar jcrombez avatar philippe-levan avatar torchello avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

symfony-docker's Issues

Debian squeeze

In order to get PHP 5.3 i tried using debian/squeeze, but...

Starting to clone
Cloning into '.'...
Cloning done
Starting Build
KernelVersion: 3.13.0-40-generic
Os: linux
BuildTime: 2016-02-22T21:37:01.910365059+00:00
ApiVersion: 1.22
Version: 1.10.2
GitCommit: c3959b1
Arch: amd64
GoVersion: go1.5.3
Starting build of index.docker.io/kitpages/symfony:5.3...
Step 1 : FROM debian:squeeze
 ---> a873733ef581
Step 2 : MAINTAINER Elie Charra <elie.charra [at] kitpages.fr>
 ---> Running in e44799cbfcb6
 ---> ea1389d1ea32
Removing intermediate container e44799cbfcb6
Step 3 : RUN apt-get -qq update && apt-get -qq -y --no-install-recommends install     supervisor     ca-certificates     nginx     php5     php5-cli     php5-intl     php5-fpm &&    apt-get clean &&     rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* &&    php -r "readfile('https://getcomposer.org/installer');" | php --              --install-dir=/usr/local/bin              --filename=composer &&    echo 'clear_env = no' >> /etc/php5/fpm/pool.d/www.conf &&    sed -i -e "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" /etc/php5/fpm/php.ini &&    echo "daemon off;" >> /etc/nginx/nginx.conf
 ---> Running in 0fd96677a8af
�[91mW: Failed to fetch http://httpredir.debian.org/debian/dists/squeeze/main/binary-amd64/Packages.gz  404  Not Found [IP: 128.31.0.66 80]

W: Failed to fetch http://httpredir.debian.org/debian/dists/squeeze-updates/main/binary-amd64/Packages.gz  404  Not Found [IP: 5.153.231.35 80]

W: Failed to fetch http://httpredir.debian.org/debian/dists/squeeze-lts/main/binary-amd64/Packages.gz  404  Not Found [IP: 5.153.231.35 80]

E: Some index files failed to download, they have been ignored, or old ones used instead.
�[0mRemoving intermediate container 0fd96677a8af
The command '/bin/sh -c apt-get -qq update && apt-get -qq -y --no-install-recommends install     supervisor     ca-certificates     nginx  

Looks like it's not really supported... it would be nice to find an other way to get php 5.3.

configuration file www.conf modified by you or by a script with php7.1-fpm

I use a DockerFile with an apt-get install that modifies the www.conf in /etc/php7.1/ftp/pool.d/www.conf

Then during the build I've got the following error :

Setting up php7.1-fpm (7.1.16-1+0~20180405085551.16+jessie~1.gbp4937aa) ...

Configuration file '/etc/php/7.1/fpm/pool.d/www.conf'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** www.conf (Y/I/N/O/D/Z) [default=N] ? dpkg: error processing package php7.1-fpm (--configure):
 EOF on stdin at conffile prompt

and the build fails.

The dockerfile of kibatic/symfony should not modify www.conf, but should instead do the modification inside another file that modifies the www pool (in this line for example)

https://github.com/kibatic/symfony-docker/blob/master/7.1/Dockerfile#L30

Best regards,
Philippe

PHP 8 support

Hey! Do you have plans on adding support for PHP 8? Need help?

directory structure for symfony 4

Hi,

The defaut nginx configuration is not compatible with symfony 4.

The public directory is now "public/" and the index file is index.php and not app.php or app_dev.php.

It is very easy to find a workaround. We just have replace the default virtual host like described in the readme. But it would be even easier to define a env variable like for example : DIRECTORY_STRUCTURE_FLAVOR=symfony4 or DIRECTORY_STRUCTURE_FLAVOR=symfony2.

Best regards,
Philippe

Change log stream path

It's dangerous to put LOG_STREAM in /tmp, most of the time we clean /tmp after doing and apt install like

    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* &&\

Add support for reverse proxy in log format ?

The idea is to add the real client ip in the access log when behind a reverse proxy.

I'm not sure if it's something this image should do or if this should be added through a custom nginx configuration by each project using it...

Add tests

Passing parameters to symfony through env variables is not covered by tests (we need to cover clear_env php fpm directive)

We need to tests logs too, retrieve docker logs of running container and ensure symfony logs are returned.

Bad owner of /var/www

/var/www should be owned by www-data

This implies permissions issues when for example you are ignoring /var/ in your dockerignore, symfony is not unable to create the folder on startup

Add support for composer 2

👋

It would be nice to have composer 2 integration, currently (in 7-.4 at least) it's still composer 1.

Rebuild this image will update to composer 2.

Nginx 50x.html page not found

When nginx try to show an error 500, it tries to loag the 50x.html page, but the fild can't be found and it create a 404 error.

2016/02/09 15:48:30 [error] 17#0: *6 open() "/usr/share/nginx/www/50x.html" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock", host: "172.17.0.7"
172.17.0.1 - - [09/Feb/2016:15:48:30 +0000] "GET / HTTP/1.1" 404 200 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36"

config nginx defined in site-enabled instead of site-available

Hi,

In the rootfs, the nginx config is defined in site-enabled and not site-avaiaible.

cf : https://github.com/kibatic/symfony-docker/tree/master/5.6/rootfs/etc/nginx/sites-enabled/default

This file should be in site-available and the config file in site-enabled should be a link to the site-available.

It introduces problems with sub dockers that mount the site-available/default file to change the config, and it doesn't work anymore.

Best regards,
Philippe

Allow to bind mount default nginx configuration

Bind mounting /etc/nginx/sites-enabled/default is actually not possible because we are symlink symfony config at runtime (which is probably a bad behaviour)

image

We need to find a solution to enable usage of defaut SF3 / SF4 config but with the possibility to bind mount a custom config.

Workaround: bind mount the symlink destination

Missing xml extension for php7.1

Symfony requires the xml extension in order to load service definitions. Adding the package php7.1-xml should be enough to fulfil this requirement.

Run scripts on container boot easily (help migration)

Database migrations are problematic when you can't run command in your container after a deployment (for a multitude of reasons). Even if you can, it adds compexity to your continuous deployment pipeline.

It might needs some testing but database migration should work if ran on each container start.
A nice way to make this optional and customizable would be something similar to "site-enabled"/"site-available" but with bash scripts that would be ran by the container if present.

Then this image could provide with some classic use cases like doctrine migrations.

Also this would be a good place to put a "dirty" permissions fix and removing it from the default behavior of this image as it's taking time while not being needed most of the time. As a matter of fact, it should never be needed if all the operations involving Symfony's commands are done as www-data (something we should add to the doc). The only good place a "permissions set" might be is the end of the Dockerfile.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.