4. Docker compose

Contents

    Note: Docker compose can be used with a single container, in order to simplify (and document) a complex command line.

    Commands

    docker-compose up

    docker-compose down

    docker-compose ps
    → to be executed in the directory of a docker-compose.yml file

    docker-compose.yml basic example

    version: "3"
    
    services:
    
      # very basic setup
      web:
        image: steveltn/https-portal:1
        environment:
          ...
        ports:
          - 80:80
          - 443:443
    
      # not using an image, but a docker file located into ./service1
      # wa have a restart policy as well
      myservice1:
        build: ./service1
        restart: always
    
      # custom Dockerfile name
      myservice2:
        build:
          context: ./service2
          dockerfile: Dockerfile.service2
        restart: always
    
      # custom CMD 
      myservice3:
        image: bash
        command: echo hello world
    

    restart policies

    Environment

    There are two syntaxes

    depends_on

    Express dependency between services. Service dependencies cause the following behaviors:

    Simple example:

    version: "3.8"
    services:
      web:
        build: .
        depends_on:
          - db
          - redis
      redis:
        image: redis
      db:
        image: postgres
    

    Proudly Powered by Zim 0.75.2.

    Template by Etienne Gandrille, based on ZeroFiveEight and using JQuery Toc Plugin.