Dockerized your web environment using PHP7.4, NGINX, COMPOSER, PHPUNIT, PHP-CS-FIXER, XDEBUG.
This repository uses official PHP and NGINX containers.
- Docker Machine
- Docker Engine
- Docker Compose
- Make (or not)
- Maybe a suggestion ? So add your contribution !
app/
public/
src/
tests/
...
docker/
nginx/
php/
docker-compose.override.yml.dist
docker-compose.yml
Makefile
README.md
Assuming you have a running docker machine, create and add your own config ./docker-compose.override.yml
, based on the dist one.
Then let's run docker-compose :
$ docker-compose up -d
$ docker-compose exec -T php /usr/local/bin/entrypoint composer install -d /srv/app/ --prefer-dist
Or if you want use the project's Makefile :
$ make install
$ make exec:composer ARGS="update -d /srv/app/"
See other commands in it, such as clear, kill and so on.
Go on : http://localhost:8080/ (or other ports specified in your ./docker-compose.override.yml
)
# shell commands
$ docker-compose exec php /usr/local/bin/entrypoint sh
# Composer (e.g. composer update)
$ docker-compose exec -T php /usr/local/bin/entrypoint composer update -d /srv/app
# Retrieve an container IP Address (here for the http one with nginx container_name)
$ docker inspect --format '{{ .NetworkSettings.Networks.dockersymfony_default.IPAddress }}' $(docker ps -f name=nginx -q)
$ docker inspect $(docker ps -f name=nginx -q) | grep IPAddress
# Check container CPU consumption
$ docker stats $(docker inspect -f "{{ .Name }}" $(docker ps -q))
# Delete all containers
$ docker stop $(docker ps -aq)
$ docker rm $(docker ps -aq)
# Delete all images
$ docker rmi $(docker images -q)
Default configuration is already set, see ./docker/php/conf.d/*.ini
.
Do not hesitate to add your xdebug.remote_host
and configure your IDE, according to the current configuration.
- E.g. :
$ docker-compose exec -T php /usr/local/bin/entrypoint /srv/app/vendor/bin/phpunit --configuration /srv/app/phpunit.xml.dist /srv/app/tests
$ docker-compose exec -T php /usr/local/bin/entrypoint php-cs-fixer fix app/src/ --rules=@PSR2
The default application path is located at ./app/public/index.php
.
You will need to alter the application path depending on your specific needs, e.g. if using
Symfony, create a Symfony directory with all the application in it and change your NGINX conf & volumes path to ./app/symfony/public/index.php
.
You can also add a Makefile to be comfortable with Docker commands.
If you want persist some data to your application you can add these containers to your docker-compose.yml
:
database:
image: mariadb:latest
container_name: mariadb
working_dir: /srv
restart: always
And to your docker-composer.override.yml.dist
:
database:
volumes:
- "./data/db:/var/lib/mysql"
environment:
- MYSQL_DATABASE=<YOUR_DB_NAME>
- MYSQL_USER=<YOUR_DB_USER>
- MYSQL_PASSWORD=<YOUR_DB_PASSWORD>
- MYSQL_RANDOM_ROOT_PASSWORD=yes
ports:
- "3306:3306"
# http://localhost:8008/?server=database
adminer:
image: adminer:latest
container_name: adminer
working_dir: /srv
restart: on-failure
ports:
- "8008:8080"
links:
- database
Do not hesitate to improve this repository, creating your PR on GitHub with a description which explains it.
Ask your question on gaetan.role@gmail.com
.