Basic System Setup

Preparation of Docker Partition

Docker requires an XFS or BTRFS file system partition in order to enforce disk quotas (see Docker Manual about storage driver options.

Docker Installation

Preparations to Run Docker Compose Files as Services

We assume that systemd is running and operational. To support running docker compose files as services, perform the following steps:

[Unit]
Description=%i service with docker compose
Requires=docker.service
After=docker.service

[Service]
Restart=always

WorkingDirectory=/etc/docker/compose/%i

# Remove old containers, images and volumes
ExecStartPre=/usr/bin/docker-compose down -v
ExecStartPre=/usr/bin/docker-compose rm -fv
ExecStartPre=-/bin/bash -c 'docker volume ls -qf "name=%i_" | xargs docker volume rm'
ExecStartPre=-/bin/bash -c 'docker network ls -qf "name=%i_" | xargs docker network rm'
ExecStartPre=-/bin/bash -c 'docker ps -aqf "name=%i_*" | xargs docker rm'

# Compose up
ExecStart=/usr/bin/docker-compose up

# Compose down, remove containers and volumes
ExecStop=/usr/bin/docker-compose down -v

[Install]
WantedBy=multi-user.target

You can start docker compose files named docker-compose.yml in a folder /etc/docker/compose/x by using the command systemctl start docker-compose@x

Setup of Reverse Proxy

Basically, you can use any reverse proxy but we decided for Traefik because of its native docker support.

logLevel = "INFO"
defaultEntryPoints = ["https","http"]

[api]
  entryPoint = "traefik"
  dashboard = true
  address = "127.0.0.1:8080"

[entryPoints]
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
    entryPoint = "https"
  [entryPoints.https]
  address = ":443"
  [entryPoints.https.tls]

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "build.mdsd.tools"
watch = true
exposedByDefault = false

[acme]
email = "someone@example.org"
storage = "/acme.json"
entryPoint = "https"
onHostRule = true
onDemand = false

  [acme.httpChallenge]
  entryPoint = "http"
version: '2'

services:
  traefik:
    image: traefik
    restart: always
    ports:
      - 80:80
      - 443:443
      - 127.0.0.1:8080:8080
    networks:
      - web
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /media/data/traefik/traefik.toml:/traefik.toml
      - /media/data/traefik/acme.json:/acme.json
    container_name: traefik

networks:
  web:
    external: true

Setup Jenkings

We have to have a custom version of the jenkins image to use docker from within the jenkins container. A manual to create this image is available at the Jenkins configuration manual. We present the basic configuration here.

version: '2'

services:
  jenkins:
    image: new_jenkins:latest
    restart: always
    user: "1500"
    expose:
      - 8080
    networks:
      - web
    volumes:
      - /media/data/jenkins:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
    container_name: jenkins
    labels:
      - "traefik.enable=true"
      - "traefik.backend=jenkins"
      - "traefik.frontend.rule=Host:jenkins.build.mdsd.tools"
      - "traefik.port=8080"
      - "traefik.docker.network=web"

networks:
  web:
    external: true