This project intends to provide various php docker configurations as templates for new projects.
Feel free to comment, test, fix, contribute or add your own template.
- master - providing php, nginx and mysql + symfony skeleton & Doctrine
- php-nginx - basic php and nginx setup
- php-nginx-mysql - basic php, nginx and mysql setup
- php-nginx-composer - basic php and nginx setup + composer
- php-nginx-mysql-composer - basic php, nginx and mysql setup + composer
- php-nginx-symfony - basic php and nginx setup + symfony skeleton
- php-nginx-mysql-symfony - basic php, nginx and mysql + symfony skeleton & Doctrine
The simplest way to start the webserver and php-fpm containers is to use docker-compose
by running:
jdoe@host:/home/jdoe/projects/app $ docker-compose up -d
Run cron-jobs or any other command by starting a new container:
jdoe@host:/home/jdoe/projects/app $ docker-compose run [--rm] app php --version
PHP 7.3.9 (cli) (built: Sep 12 2019 10:23:43) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
Hook into running container to run your php software inside its environment:
jdoe@host:/home/jdoe/projects/app $ docker-compose exec app bash -l
root@app:/var/www/app# php --version
PHP 7.3.9 (cli) (built: Sep 12 2019 10:23:43) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
The same for a fresh container instance:
jdoe@host:/home/jdoe/projects/app $ docker-compose run --rm app bash -l
root@app:/var/www/app# php --version
PHP 7.3.9 (cli) (built: Sep 12 2019 10:23:43) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
The docker image has two stages for development and production. This way development can take place inside the same environment. For the development stage, debugging settings are enabled.
The basic docker-compose.yml is intended to be extended by overrides and is therefore very minimal (no port mappings e.g.). Extend it by adding your customized override file. Templates are provided for development and production. The development override mounts the project directory from the host machine to enable rapid development inside the container.
The latest master version of composer (https://getcomposer.org) is installed. Use it from a running container to manage your app:
jdoe@host:/home/jdoe/projects/app $ docker-compose exec app bash -l
root@app:/var/www/app# composer --version
Composer version 1.9.0 2019-08-02 20:55:32
... or run it inside a fresh container, if you prefer:
jdoe@host:/home/jdoe/projects/app $ docker-compose run --rm app bash -l
root@app:/var/www/app# composer --version
Composer version 1.9.0 2019-08-02 20:55:32
The symfony 4.3 skelleton, as well as the symfony installer is part of the project. Use the skeleton or remove
it and use the symfony
command to create a new project.
jdoe@host:/home/jdoe/projects/app $ docker-compose run --rm app bash -l
root@app:/var/www/app# symfony new myapp
...
Use the symfony console from running container:
jdoe@host:/home/jdoe/projects/app $ docker-compose exec app bash -l
root@app:/var/www/app# bin/console cache:clear
...