Docker-compose

Docker Compose

  • A tool to run multiple containers

  • Insllation: apt install docker-compose

Commands:

  • docker-compose up [-d] [--build]

  • docker-compose down

  • docker-compose restart

Example of docker-compose.yml

  • Running 1 nginx proxy named management, 1 oxidized and 1 backupmgmt

version: '3'

services:
    management:
        image: nginx
        container_name: management
        ports:
            - 10.10.10.1:80:80
            - 10.10.10.1:443:443
        volumes:
            - /etc/nginx:/etc/nginx/conf.d/
            - /storage:/storage
            - /etc/localtime:/etc/localtime:ro
        restart: always
        extra_hosts:
        - "host.docker.internal:host-gateway"

    oxidized:
        depends_on:
            - management
        image: oxidized:latest
        container_name: oxidized
        expose:
            - "8888"
        volumes:
            - /etc/oxidized:/root/.config/oxidized
            - /etc/localtime:/etc/localtime:ro
        restart: always
        command: /root/.config/oxidized/startup.sh

    backupmgmt:
        depends_on:
            - management
        image: gunicorn
        container_name: backupmgmt
        expose:
            - "80"
        volumes:
            - /storage/backupmanagement:/app
            - /storage/backup:/storage/backup
        command: /app/gunicorn.sh

Some Errors

nginx: [emerg] host not found in upstream “host.docker.internal:8888” in /etc/nginx/conf.d/nginx.conf:3

  • nginx container is configured as a proxy for a another container named oxidizedcontainer

Configuration of NGINX:

  • Reason: docker can’t find host defined in upstream

Solution 1: Using extra_hosts: host.docker.internal

  • Nginx uses host IP to access upstream. This requires -p : on upstream containers

  • External users can access upstream container directly if -p listen on 0.0.0.0 or external IP

Solution 2

  • Using docker-compose to run both proxy and oxidizedcontainer

  • Using this, oxidized container doesn’t need to be published, just need to be exposed. This is because by default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.

Configuration of docker-compose.yml

Configuration of nginx.conf

  • Note: indentation is important

Last updated