Skip to content

Instantly share code, notes, and snippets.

@stewartadam
Last active October 11, 2022 17:13
Show Gist options
  • Save stewartadam/be29c0a7c872cfb74247b56dcb7ee716 to your computer and use it in GitHub Desktop.
Save stewartadam/be29c0a7c872cfb74247b56dcb7ee716 to your computer and use it in GitHub Desktop.
systemd configuration for containers on boot with docker-compose (via linuxserver.io, among others)

Overview

This sample is intended for modern Linux systems using systemd (Fedora, Ubuntu, Arch, etc).

Installation

Install the files in this gist, replacing dashes for slashes (e.g. etc-systemd-system-dockercompose.service should be installed to /etc/systemd/system/dockercompose.service) and then run systemctl enable --now dockercompose.service to get things started.

Usage

Any manual docker-compose commands should be run from /srv/appdata/linuxserver so that the values from the .env file are applied properly.

Log files can be viewed by running docker-compose -f --tail=50.

Container images can be updated by running docker-compose pull --parallel.

[Unit]
Description=Docker Compose Service
After=docker.service
Requires=docker.service
[Service]
WorkingDirectory=/srv/appdata/linuxserver
ExecStartPre=/usr/bin/docker-compose -f /srv/appdata/linuxserver/docker-compose.yml down
ExecStart=/usr/bin/docker-compose -f /srv/appdata/linuxserver/docker-compose.yml up
ExecStop=/usr/bin/docker-compose -f /srv/appdata/linuxserver/docker-compose.yml stop
TimeoutSec=120
[Install]
WantedBy=multi-user.target
# Run me to generate the .env file
cat << EOF > /srv/appdata/linuxserver/.env
TZ=$(timedatectl status | grep 'Time zone' | sed -r 's/ +Time zone: (.*) \(.*/\1/')
UID=$(id -u)
GID=$(id -g)
HOSTNAME=$(hostname -s)
DUCKDNS_SUBDOMAINS=foo,bar
DUCKDNS_TOKEN=guid-here
EOF
---
version: "2.2"
# version 2.2 instead of 3 because of requirement of 'init: true' for unifi, which hasn't been added to v3 yet
services:
plex:
image: plexinc/pms-docker
container_name: plex
volumes:
- /var/lib/plexmediaserver:/config
- /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache:/transcode
- /media/home_videos:/data
network_mode: host
restart: unless-stopped
environment:
- TZ=${TZ}
- HOSTNAME=${HOSTNAME}
- PLEX_UID=${UID}
- PLEX_GID=${GID}
tautulli:
image: linuxserver/tautulli
container_name: tautulli
depends_on:
- plex
volumes:
- /srv/appdata/tautulli:/config
- /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs:/logs:ro
restart: unless-stopped
environment:
- TZ=${TZ}
hostname: ${HOSTNAME}
ports:
- 8181:8181
duckdns:
image: linuxserver/duckdns
container_name: duckdns
environment:
- TZ=${TZ}
- SUBDOMAINS=${DUCKDNS_SUBDOMAINS}
- TOKEN=${DUCKDNS_TOKEN}
restart: unless-stopped
home-assistant:
image: homeassistant/home-assistant
container_name: home-assistant
network_mode: host
restart: unless-stopped
volumes:
- /srv/appdata/home-assistant:/config
- /etc/localtime:/etc/localtime
unifi:
image: jacobalberty/unifi:stable
container_name: unifi
init: true
environment:
- TZ=${TZ}
- RUNAS_UID0=false
- UNIFI_UID=${UID}
- UNIFI_GID=${GID}
restart: unless-stopped
ports:
- 8080:8080
- 8443:8443
- 8843:8843
- 8880:8880
- 3478:3478/udp
volumes:
- /srv/appdata/unifi:/unifi
muximux:
image: linuxserver/muximux
container_name: muximux
restart: unless-stopped
environment:
- TZ=${TZ}
- PUID=${UID}
- PGID=${GID}
ports:
- 8081:80
volumes:
- /srv/appdata/muximux:/config
@ytechie
Copy link

ytechie commented Nov 7, 2018

The service references docker-compose.yml, but you have the file name as docker-compose.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment