Примерно так выглядит мой конфиг для local development with symfony.
Это
не продакшн конфиг.
docker-compose.yml
version: '2'
services:
nginx:
build: ./docker/nginx
ports:
- "80:80"
links:
- php
volumes:
- ./docker/nginx/http.conf:/etc/nginx/conf.d/http.conf
- ./docker/nginx/site.conf:/etc/nginx/sites-enabled/site.conf
volumes_from:
- php
command: 'nginx -g "daemon off;"'
php:
build: ./docker/php
volumes:
- .:/src
- ./docker/php/php-cli.ini:/etc/php/7.0/cli/conf.d/php-cli.ini
- ./docker/php/php-fpm.ini:/etc/php/7.0/fpm/conf.d/php-fpm.ini
- ./docker/php/pool.conf:/etc/php/7.0/fpm/pool.d/www.conf
command: 'php-fpm7.0 -F'
links:
- db
- cache
environment:
SYMFONY__DB__DRIVER: pdo_pgsql
SYMFONY__DB__HOST: db
SYMFONY__DB__PORT: 5432
SYMFONY__DB__NAME: dbname
SYMFONY__DB__USER: dbuser
SYMFONY__DB__PASSWORD: dbpassword
db:
image: "postgres:latest"
environment:
POSTGRES_DB: dbname
POSTGRES_USER: dbuser
POSTGRES_PASSWORD: dbpassword
cache:
image: "redis:latest"
command: redis-server --appendonly yes
docker/nginx/Dockerfile
FROM ubuntu:16.04
RUN apt-get update \
&& apt-get install -y nginx
docker/nginx/http.conf
access_log /dev/stdout;
error_log /dev/stderr;
docker/nginx/site.conf
server {
listen 80;
server_name example.dev;
root /src/web;
index index.php index.html;
location / {
try_files $uri /app_dev.php$is_args$args;
}
location ~ ^/(app_dev|config)\.php(/|$) {
include fastcgi.conf;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass php:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location ~ \.php$ {
return 404;
}
}
docker/php/Dockerfile
FROM ubuntu:16.04
ENV PHP_PACKAGES \
php7.0-fpm \
php7.0-cli \
php7.0-readline \
php7.0-pgsql \
php7.0-mcrypt \
php7.0-xml
RUN apt-get update \
&& apt-get install -y $PHP_PACKAGES
RUN usermod -u 1000 www-data
docker/php/php-cli.ini
error_reporting = -1
display_errors = On
log_errors = Off
html_errors = Off
docker/php/php-fpm.ini
error_reporting = -1
display_errors = On
log_errors = Off
html_errors = On
cgi.fix_pathinfo = 0
docker/php/pool.conf
pid = /var/run/php.pid
[www]
user = www-data
group = www-data
listen = 0.0.0.0:9000
pm = dynamic
pm.max_children = 20
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
clear_env = no
catch_workers_output = yes
Как разворачивать базу
Читайте про docker-entrypoint-initdb.d
Либо же
docker cp file.sql.gz containername:/tmp/dump.sql.gz
docker exec -ti containername bash
gunzip -c /tmp/dump.sql.gz | psql -U username dbname