Docker-compose

Docker compose-al, több docker konténert kezelhetünk egyszerre. Erre nézünk egy rövid példát. Tartalmazni fogja a pgsql-t, pgsqladmin-t, nginx-et, php-fpm-et.

Telepítés:
 
# apt-get install docker-compose


A konfigurációs fájl docker-compose.yml:
 
version: "3.1"
services:

    postgres:
      image: postgres
      container_name: postgres
      volumes:
         - "./sourcefiles/postgres:/var/lib/postgresql/data"
      environment:
        - POSTGRES_USER=${POSTGRES_USER}
        - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
        - POSTGRES_DB=${POSTGRES_DB}
      ports:
       - "5432:5432"
      networks:
            testing_net:
                ipv4_address: 172.28.1.2

    webserver:
      image: nginx:alpine
      container_name: ${PROJECT_NAME}-webserver
      working_dir: /application
      volumes:
          - ./application:/application
          - ./sourcefiles/nginx:/etc/nginx/conf.d
      ports:
       - "80:80"
      networks:
           testing_net:
                ipv4_address: 172.28.1.3

    php-fpm:
      build: sourcefiles/php-fpm
      container_name: ${PROJECT_NAME}-php-fpm
      working_dir: /application
      volumes:
        - ./application:/application
        - ./sourcefiles/php-fpm/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini
      networks:
         testing_net:
              ipv4_address: 172.28.1.4


    pgadmin:
      image: dpage/pgadmin4
      depends_on:
        - postgres
      ports:
        - "5555:80"
      environment:
        PGADMIN_DEFAULT_EMAIL: pgadmin4@pgadmin.org
        PGADMIN_DEFAULT_PASSWORD: admin
      restart: unless-stopped
      networks:
        testing_net:
            ipv4_address: 172.28.1.5

networks:
   testing_net:
       ipam:
          driver: default
          config:
             - subnet: 172.28.0.0/16

Nginx config sourcefiles/nginx/nginx.conf:
 
server {
    listen 80 default;

    client_max_body_size 108M;

    access_log /var/log/nginx/application.access.log;


    root /application/public;
    index index.php;

    if (!-e $request_filename) {
        rewrite ^.*$ /index.php last;
    }

    location ~ \.php$ {
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        include fastcgi_params;
    }
    
}

Php docker file sourcefiles/php-fpm/Dockerfile:
 
FROM phpdockerio/php74-fpm:latest
WORKDIR "/application"

# Fix debconf warnings upon build
ARG DEBIAN_FRONTEND=noninteractive

# Install selected extensions and other stuff
RUN apt-get update \
    && apt-get -y --no-install-recommends install php7.4-pdo php7.4-pgsql php7.4-cli php7.4-gd \
    && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

# Install git
RUN apt-get update \
    && apt-get -y install git \
    && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*


Php ini file sourcefiles/php-fpm/php-ini-overrides.ini
 
upload_max_filesize = 100M
post_max_size = 108M

A sourcefiles/postgres mappába az adatbázis fájlok kerülnek.

Parancsok:
 
Indítás:
# docker-compose up -d

Ha más config fájlunk van megadhatjuk a fájlnevét:
# docker-compose up -d -f docker-compose-test.yml

Leállítás:
# docker-compose down


Olvasnivaló:

https://github.com/thayronarrais/docker-laravel-postgres-nginx
https://stackoverflow.com/questions/25540711/docker-postgres-pgadmin-local-connection
https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html
https://linuxhint.com/postgresql_docker/
https://hasura.io/blog/building-graphql-api-laravel-postgresql-hasura-remote-joins/
https://medium.com/coderbunker/a-better-way-to-develop-your-graphql-api-using-docker-postgresql-postgraphile-7a1ae034b826
2021.05.02.