見出し画像

[docker] docker compose へお引っ越し [ubuntu]

冬休み入ったころに購入した linux サーバが冬休みの終わりを告げるころになっても何もセットアップされていないことに気がついて、ちょっとばかし作業してみました。

既に docker でサービスしていたものは移行しやすいので、まずは unbound (+logspout) を移行しました。

unbound を docker で起動するようなケースで、ubuntu の場合 53/tcp, 53/udp は systemd-resolved が使っている所為で競合します。ポートを変更してもいいんだけど、そもそも resolved を使わないので、systemd-resolved は disable して過ごしてます。これが ubuntu 的に正解かは知らない。わが家的には困っていない。

ただ移行するだけじゃつまらないので、docker compose でまとめて動かせるようにしました。次の2つ docker.io と docker-compose-v2 パッケージの追加が必要です。

  • docker.io

  • docker-compose-v2

$ sudo apt install docker.io
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  bridge-utils containerd dns-root-data dnsmasq-base git git-man iptables less
  liberror-perl libip6tc2 libnetfilter-conntrack3 libnfnetlink0 libnftnl11
  netcat netcat-openbsd patch pigz runc ubuntu-fan
Suggested packages:
  ifupdown aufs-tools cgroupfs-mount | cgroup-lite debootstrap docker-doc
  rinse zfs-fuse | zfsutils git-daemon-run | git-daemon-sysvinit git-doc
  git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn firewalld
  nftables ed diffutils-doc
The following NEW packages will be installed:
  bridge-utils containerd dns-root-data dnsmasq-base docker.io git git-man
  iptables less liberror-perl libip6tc2 libnetfilter-conntrack3 libnfnetlink0
  libnftnl11 netcat netcat-openbsd patch pigz runc ubuntu-fan
0 upgraded, 20 newly installed, 0 to remove and 0 not upgraded.
Need to get 74.8 MB of archives.
After this operation, 292 MB of additional disk space will be used.
Do you want to continue? [Y/n] Get:1 http://jp.archive.ubuntu.com/ubuntu jammy/universe amd64 pigz amd64 2.6-1 [63.6 kB]
:
(中略)
:
Created symlink /etc/systemd/system/multi-user.target.wants/ubuntu-fan.service → /lib/systemd/system/ubuntu-fan.service.
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.5) ...
Daemons using outdated libraries
--------------------------------


$ sudo apt install docker-compose-v2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  docker-compose-v2
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.5 MB of archives.
After this operation, 53.4 MB of additional disk space will be used.
:
(後略)

これで docker も docker compose もいずれも使えるようになります。
あとは docker-compose.yml を書いて、docker compose up -d すれば良いだけです。
実際の設定ファイルはこんな感じです。設定変更しても必要な箇所だけ自動的に再起動が入るようになるので確かに楽なんですよね。なんで今までやっていなかったのか。

services:
  unbound:
    image: klutchell/unbound
    ports:
      - "53:53/tcp"
      - "53:53/udp"
    volumes:
      - /var/lib/docker/unbound:/etc/unbound/custom.conf.d
    restart: always

  logspout:
    image: gliderlabs/logspout
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command: syslog+udp://logs???.papertrailapp.com:?????
    environment:
      - SYSLOG_HOSTNAME=${HOSTNAME}
    restart: always

環境変数にとあるコマンドの実行結果埋めたかったけど、ちょっと分からなかったので別の環境変数を見るようにさせて .env ファイルを作りました。

docker compose にしたのは、イメージの更新があったときに対応が楽になるかなと考えての策です。ゆくゆくは自動化しちゃおうかなとか、こんな感じの気持ちはあります。

compose ファイルのリファレンス見ながら、洗練させていきます 🙏


この記事が参加している募集

今年やりたい10のこと

貴方がサポートしてくれると、私が幸せ。 私が幸せになると、貴方も幸せ。 新しいガジェット・ソフトウェアのレビューに、貴方の力が必要です。