B
B
bernex2016-07-27 12:34:41
Web development
bernex, 2016-07-27 12:34:41

How to create the correct docker file for a project?

There is a php+postgres project.
There is a desire to correctly lift the docker for development on locales. How to do it right? Should there be one image? Or separately php, separately postgres?
So that later it will be in the repository and always easily lifted on all platforms.
How to expand the base into it correctly?
In general, there were acquaintances and experiments with the docker.
But how to do it correctly in terms of the correctness of the DevOps process, and not crutches.
There are examples?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Osher, 2016-07-27
@miraage

This is what my config for local development with symfony looks like.
This is not a production config.
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

Read about docker-entrypoint-initdb.d
Or
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

N
Nazar Mokrinsky, 2016-07-27
@nazarpc

Everything is separate, for persistent data, mount the volume (volume) that you use between restarts.
I have an example of a whole set of containers for PHP, but there is no PostgreSQL, if you are kind enough to add it will be great, but as an example it will do: https://github.com/nazar-pc/docker-webserver

P
podavo, 2017-07-04
@podavo

minikube

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question