Skip to main content

Docker Compose

====================================================================================

Installation

Install Docker Compose (and docker.io if not installed already)
apt install docker.io docker-compose

====================================================================================

YAML (Yet Another Markup Language)

YAML files are just text files that are used by Docker-Compose for definition of image/container setup. YAML files are a very useful feature of Docker as they all for deployment of containers on any system by just using the YAML file.

NOTE; YAML files are VERY picky about their syntax - this includes character positioning.

Basic annotated example;

version: '3.7' #defines docker-compose version to use
services:
  portainer:
    container_name: container1 #define the name to be assigned to the container
    image: portainer/portainer-ce #define the image to be used for the container
    command: -H unix:///var/run/docker.sock #command to be run on the container once it starts - varies depending on application
    restart: 'always' #set container to start on boot
    ports: #network definition
      - target: '9000'
        published: '9000' #define the port for container to listen on externally
        protocol: tcp #protocol definition
      - target: '8000'
        published: '8000' #define additional port for container to listen on externally
        protocol: tcp #protocol definition
    volumes: #definition of storage volumes
      - type: bind #container storage will be bound to a physical file on the underlying host
        source: /var/run/docker.sock #define docker.sock file to allow container to use this
        target: /var/run/docker.sock #define the docker.sock file for within the container. Essentially mapping the 2 files together.
      - type: bind
        source: /srv/portainer
        target: /data/

Start the container based on YAML file:

docker-compose up --detatch

====================================================================================