An example project that uses the following techniques:
- Symfony 5.3
- PHP 8.0
- PHPUnit 9.5
- PHPStan 0.12
- GitHub
- Docker Hub
- CI/CD Integration with GitHub
- Semantic Versioning 2.0.0
Create a file named docker-compose.yml with the following content:
# ===========================================# ❯ mkdir docker-compose && cd docker-compose# ❯ vi docker-compose.yml# ===========================================version: "3.8"# Configure servicesservices:
# Nginx to serve the app.nginx:
image: "nginx:latest"container_name: "de.ixno.php-json-beautifier.nginx"hostname: "de-ixno-php-json-beautifier-nginx"restart: alwaysports:
- 8000:80volumes:
# Server static pages (uses the data from php service)
- data:/var/www/web# Add nginx configuration (uses the data from php service)
- nginx_config:/etc/nginx/conf.ddepends_on:
- php
- composer# Use ixnode/php-json-beautifier:latest image (originated from image php:8.0.11-fpm) with the data it containsphp:
image: "ixnode/php-json-beautifier:latest"container_name: "de.ixno.php-json-beautifier.php"hostname: "de-ixno-php-json-beautifier-php"restart: alwaysvolumes:
# This container shares the folder /var/www/web via volume data, because the container starts# first and the content already exists
- data:/var/www/web# This container shares the folder /var/www/web/docker/nginx/conf.d via volume nginx_config, because# the container starts first and the content already exists
- nginx_config:/var/www/web/docker/nginx/conf.d# Composer image: This container is executed once and performs a composer install.composer:
image: "composer:latest"container_name: "de.ixno.php-json-beautifier.composer"hostname: "de-ixno-php-json-beautifier-composer"command: ["composer", "install"]volumes:
- data:/app # This container shares the folder /app via volume data, because it already exists# Configure volumesvolumes:
data:
name: "de.ixno.php-json-beautifier.volume.data"nginx_config:
name: "de.ixno.php-json-beautifier.volume.nginx.config"If you like nicely named projects, use the .env file
# @see https://docs.docker.com/compose/reference/envvars/#compose_project_name# ❯ vi docker-compose/.env
COMPOSE_PROJECT_NAME=de-ixno-php-json-beautifier❯ docker-compose up -d❯ docker-compose exec php bin/console app:json:beautify '{"value": "123"}'{
"value": "123"
}❯ echo'{"value": "123"}'| docker-compose exec php bin/console app:json:beautify{
"value": "123"
}