ENG | Docker (podman) compose and backup scripts, June 2023
Introduction
This post is a collection of configs as of 2023-06-25. Keep in mind they work together and they have certain dependencies on tools (such as zstandard, dash, podman). Also they reflect my knowledge of containers to that date. I may post later modifications.
Dash is sometimes used as POSIX compatible shell to avoid bash-specific syntax which is not portable. On most Linux distributions, /bin/sh
is a symlink link to bash
and sadly system scripts rely on it.
There are separate articles about Cloudflare services and setting up Nextcloud.
~/.config/systemd/user/podman-compose.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Podman Compose Service
After=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/pavel/docker
ExecStart=/usr/bin/podman-compose -f docker-compose.yml up -d
ExecStop=/usr/bin/podman-compose -f docker-compose.yml down
[Install]
WantedBy=default.target
~/docker/.env
Passwords and API tokens removed.
1
2
3
4
5
TIMEZONE=Europe/Prague
NC_MYSQL_PASSWORD=Cl....
NC_MYSQL_ROOT_PASSWORD=Ab...
CF_TOKEN=eyJh...
CF_API_TOKEN=HSH...
~/docker/docker-compose.yml
Compilation of various examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
version: "3.5"
# Changes:
# 2023-04-21: Fedora installed on Esprimo
# 2023-04-21: removed npm - first it can run on zimaboard, second it should be replaced by cloudflare tunnel
# removed networks
# 2023-04-21: copied old volumes
# 2023-04-22: cloudflared added
# 2023-05-02: nginx added
# 2023-05-05: .env file added
# 2023-06-02: cloudflare-ddns added
# 2023-06-04: hardcoded nextcloud version cause latest is broken (required `podman exec -it nextcloud-app occ upgrade` afterwards
#
# Note
# Based on original nextcloud docker compose
# and https://www.youtube.com/watch?v=iFHbzWhKfuU
#
# To stop/update/start service (defined in ~/.config/systemd/user/podman-compose.service) use:
#
# systemctl --user stop podman-compose.service
# podman-compose pull
# podman image prune
# systemctl --user start podman-compose.service
volumes:
nextcloud-db:
nextcloud-app-data:
nextcloud-app-config:
nginx-config:
services:
# Maria DB for nextcloud
# https://github.com/linuxserver/docker-mariadb/
# https://github.com/linuxserver/docker-baseimage-alpine/
nextcloud-db:
image: lscr.io/linuxserver/mariadb:latest
container_name: nextcloud-mariadb
restart: unless-stopped
environment:
- PUID=1000
- TZ=Europe/Prague
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD=${NC_MYSQL_PASSWORD}
- MYSQL_ROOT_PASSWORD=${NC_MYSQL_ROOT_PASSWORD}
volumes:
- nextcloud-db:/config
# Nextcloud application
# https://hub.docker.com/r/linuxserver/nextcloud
# https://github.com/linuxserver/docker-nextcloud/tree/master
# https://github.com/linuxserver/docker-baseimage-alpine-nginx
# https://github.com/linuxserver/docker-baseimage-alpine/
nextcloud-app:
image: lscr.io/linuxserver/nextcloud:26.0.2-ls246
container_name: nextcloud-app
environment:
- PUID=1000
- PGID=100
- TZ=Europe/Prague
# These work on official nextcloud image, not one form lscr.io :-(
#- MYSQL_HOST=nextcloud-db
#- MYSQL_DATABASE=nextcloud
#- MYSQL_USER=nextcloud
#- MYSQL_PASSWORD=Cle*****
volumes:
- nextcloud-app-config:/config
- nextcloud-app-data:/data
restart: unless-stopped
ports:
- 8081:80
depends_on:
- nextcloud-db
# Cloudflared
# https://hub.docker.com/r/cloudflare/cloudflared
# https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide/local/tunnel-useful-commands/
# https://github.com/Erisa/cloudflared-docker/tree/main
cloudflared:
container_name: cloudflared
image: docker.io/cloudflare/cloudflared:latest
# image erisamoe/cloudflared
restart: unless-stopped
environment:
- TUNNEL_TOKEN=${CF_TOKEN}
command: tunnel --no-autoupdate run
# https://github.com/oznu/docker-cloudflare-ddns
# cloudflare-ddns:
# container_name: cloudflare-ddns
# image: docker.io/oznu/cloudflare-ddns:latest
# restart: unless-stopped
# environment:
# - API_KEY=${CF_API_TOKEN}
# - ZONE=pavelp.cz
# - PROXIED=false
cloudflare-ddns:
container_name: cloudflare-ddns
image: docker.io/favonia/cloudflare-ddns:latest
restart: unless-stopped
environment:
- PUID=1000
- PGID=100
- CF_API_TOKEN=${CF_API_TOKEN}
- DOMAINS=pavelp.cz
- PROXIED=false
- IP6_PROVIDER=none
# Nginx for jekyll
nginx:
container_name: nginx
image: lscr.io/linuxserver/nginx:latest
environment:
- PUID=1000
- PGID=100
- TZ=Europe/Prague
volumes:
- nginx-config:/config
ports:
- 8080:80
restart: unless-stopped
~/bin/podman-images-update.sh
Written by me, adopted from docker
1
2
3
4
5
6
7
8
9
10
#!/usr/bin/dash
# This script updates podman images and removes old ones
# PavelP, 2023-06-02
cd ~/docker
systemctl --user stop podman-compose.service
podman-compose pull
podman image prune --force
systemctl --user start podman-compose.service
~/bin/backup-nextcloud.sh
Written by me using podman documentation being misquided by ChatGPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/dash
# Pavel Perina
# Changes:
# 2023-06-25 Initial version
# 2023-06-29 Some variables moved to .env
# 2023-07-15 Database backup as volume
#######################
# Setup variables
. $HOME/docker/.env
DATE=$(date +%Y-%m-%d)
TARGET=$HOME/backup
NEXTCLOUD_CONTAINER_ID=nextcloud-app
DATABASE_CONTAINER_ID=nextcloud-mariadb
#######################
# Backup nextcloud
# Function to enable or disable maintenance mode
toggle_maintenance_mode() {
podman exec $NEXTCLOUD_CONTAINER_ID occ maintenance:mode --$1
}
backup_nextcloud() {
echo "🛑 Bringing Nextcloud down ..."
toggle_maintenance_mode "on"
echo "💾 Backing up Nextcloud database ..."
#podman exec $DATABASE_CONTAINER_ID /usr/bin/mysqldump --user=nextcloud --password=$NC_MYSQL_PASSWORD nextcloud | zstd -9 > $TARGET/nextcloud-db-$DATE.sql.zst
podman volume export docker_nextcloud-db | zstd -9 > $TARGET/nextcloud-db-$DATE.tar.zst
echo "💾 Backing up Nextcloud config ..."
podman volume export docker_nextcloud-app-config | zstd -9 > $TARGET/nextcloud-app-config-$DATE.tar.zst
echo "💾 Backing up Nextcloud data (be patient) ..."
podman volume export docker_nextcloud-app-data | zstd -3 > $TARGET/nextcloud-app-data-$DATE.tar.zst
echo "🟢 Bringing Nextcloud up ..."
toggle_maintenance_mode "off"
echo "Nextcloud backup finished"
}
backup_nextcloud
~/bin/backup-devlog.sh
Written by me. Backups dev-blog source files used to build _site
.
Restoration should be easy.
Major part of content are npm packages which are not even part of git repository.
Since it’s roughly 100MB, I don’t care. It just might not work without running some commands to update them.
Important stuff is in git repository.
Check Jekyll install instructions.
1
2
3
4
5
6
7
#!/bin/dash
# Pavel Perina, 2023-06-25
DATE=$(date +%Y-%m-%d)
TARGET=/home/pavel/backup
echo "💾 Backing up dev-blog ..."
cd && tar c dev-blog | zstd -15 > $TARGET/dev-blog-$DATE.tar.zst
/root/.bashrc
1
2
3
4
5
# Added by me
export HISTFILESIZE=99999
export HISTSIZE=$HISTFILESIZE
shopt -s histappend
export PS1="\[\e[1;34m\][\[\e[1;31m\]\u@\[\e[1;34m\]\h\[\e[1;37m\] -=- \w\[\e[1;34m\]]\[\e[1;36m\]#\[\e[0m\] "
~/.zshrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# The following lines were added by compinstall
zstyle :compinstall filename '/home/pavel/.zshrc'
autoload -Uz compinit
compinit
# End of lines added by compinstall
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=200000
SAVEHIST=200000
setopt appendhistory
setopt EXTENDED_HISTORY
bindkey -e
# End of lines configured by zsh-newuser-install
# Trivial monocrhrome [user@host:/path]$
#export PS1="[%n@%m:%/]$ "
# Initial color version
export PS1="[%F{cyan}%n@%F{blue}%m%f -=- %/]$ "
# Install Ruby Gems to ~/gems
export GEM_HOME="$HOME/gems"
export PATH="$PATH:$HOME/bin:$HOME/.local/bin:$HOME/gems"
# Bind home and end keys
bindkey "^[[H" beginning-of-line
bindkey "^[[F" end-of-line
~/.bashrc
Added
1
2
3
# Install Ruby Gems to ~/gems
export GEM_HOME="$HOME/gems"
export PATH="$PATH:$HOME/gems"
~/.Xresources
1
2
3
4
5
6
Xft.antialias: 1
Xft.hinting: 1
Xft.rgba: rgb
Xft.hintstyle: hintslight
Xft.lcdfilter: lcddefault
Xft.dpi: 96ca
~/.gitconfig
Email hidden
1
2
3
4
5
[user]
email = (add here)
name = Pavel Perina
[init]
defaultBranch = main
~/bin/ip.php
1
2
3
4
<?php
$ip = shell_exec("curl -s ifconfig.me/ip");
echo "<p style=\"font-family: monospace;\">Public IP address is:<br />" . $ip . "</p>";
?>
~/.inputrc
This was an attempt to make home and end key work.
It does not work in zsh
, but it may fix bash.
1
2
"\e[H": beginning-of-line
"\e[F": end-of-line