仮想化の検討
今後の可用性も考えて、サーバーに載せているサービスの仮想化やコンテナ化を考えてみる。
対象はなんだろう
- samba
- gogs
- nextcloud
- mydns/グローバルIP監視
- ログインログアウト監視(Slack連携)
- MariaDB
- webmin
gogs
まずはgogs
現状
よかったメモしておいて
https://continue-to-challenge.blogspot.com/search?q=gogs
adeno@blackcube:/home/git$ systemctl status gogs
● gogs.service - Gogs (Go Git Service)
Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-01-23 04:00:09 JST; 1h 47min ago
Main PID: 2548 (gogs)
Tasks: 8 (limit: 4915)
CGroup: /system.slice/gogs.service
└─2548 /home/git/gogs/gogs web
1月 23 05:43:38 blackcube gogs[2548]: [Macaron] 2023-01-23 05:43:38: Started GET /admin/config for 192.168.1.37
1月 23 05:43:38 blackcube gogs[2548]: [Macaron] 2023-01-23 05:43:38: Completed GET /admin/config 200 OK in 21.32905ms
1月 23 05:43:38 blackcube gogs[2548]: [Macaron] 2023-01-23 05:43:38: Started GET /assets/font-awesome-4.6.3/fonts/fontawesome-webfont.woff2?
1月 23 05:43:38 blackcube gogs[2548]: [Macaron] [Static] Serving /assets/font-awesome-4.6.3/fonts/fontawesome-webfont.woff2
1月 23 05:43:38 blackcube gogs[2548]: [Macaron] 2023-01-23 05:43:38: Started GET /img/favicon.png for 192.168.1.37
1月 23 05:43:38 blackcube gogs[2548]: [Macaron] [Static] Serving /img/favicon.png
1月 23 05:43:38 blackcube gogs[2548]: [Macaron] 2023-01-23 05:43:38: Completed GET /img/favicon.png 200 OK in 2.466123ms
1月 23 05:43:38 blackcube gogs[2548]: [Macaron] 2023-01-23 05:43:38: Completed GET /assets/font-awesome-4.6.3/fonts/fontawesome-webfont.woff
1月 23 05:43:40 blackcube gogs[2548]: [Macaron] 2023-01-23 05:43:40: Started GET /admin/repos for 192.168.1.37
1月 23 05:43:40 blackcube gogs[2548]: [Macaron] 2023-01-23 05:43:40: Completed GET /admin/repos 200 OK in 107.448955ms
たぶん、ここを参考にservice化したのだろう
https://github.com/gogs/gogs/blob/main/scripts/systemd/gogs.service
adeno@blackcube:/home/git$ cat /etc/systemd/system/gogs.service
[Unit]
Description=Gogs (Go Git Service)
After=syslog.target
After=network.target
After=mysqld.service
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
Type=simple
User=git
Group=git
WorkingDirectory=/home/git/gogs
ExecStart=/home/git/gogs/gogs web
Restart=always
Environment=USER=git HOME=/home/git
[Install]
WantedBy=multi-user.target
dockerでやってみる
https://github.com/gogs/gogs/tree/main/docker
sudo docker pull gogs/gogs
mkdir -p /mnt/workarea/gogs
sudo docker run --name=gogs -p 10022:22 -p 3000:3000 -v /mnt/workarea/gogs:/data gogs/gogs
久しぶりのdockerで使い方忘れてる
あと、gogsのデータの引っ越しはどうやるんだっけ?
adeno@blackcore:~$ sudo docker ps -a
[sudo] adeno のパスワード:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5c8dba490d7e gogs/gogs "/app/gogs/docker/st…" 9 days ago Exited (0) 8 days ago gogs
データの移行
https://github.com/gogs/gogs/discussions/6876
./gogs backup
で、書き出す。gogs-backup-20230123060827.zipが生成された。
/mnt/workarea/gogsに保存すると、docker内では/dataからアクセスできる。
adeno@blackcore:~$ sudo docker exec -it gogs /bin/bash
bash-5.1# ls
data docker gogs log
bash-5.1# ./gogs -v
Gogs version 0.13.0+dev
bash-5.1# ls data/
gogs-backup-20230123060827.zip gogs.db sessions
bash-5.1#
bash-5.1# ./gogs restore --from="data/gogs-backup-20230123060827.zip"
2023/01/31 16:28:35 [ INFO] Restoring backup from: data/gogs-backup-20230123060827.zip
2023/01/31 16:28:38 [FATAL] [gogs.io/gogs/gogs.go:40 main()] Failed to start application: init configuration: user configured to run Gogs is "git", but the current user is "root"
bash-5.1#
カレントユーザーがrootになっているので、ユーザーgitで実行する
docker-compose
なんか難しそうなので、docker-composeを使ってみる
sudo apt install docker-compose
version: '3'
services:
gogs:
image: gogs/gogs:latest
container_name: gogs
restart: always
ports:
- 3000:3000
volumes:
- ./data:/data
links:
- mariadb:db
mariadb:
image: mariadb:latest
restart: always
ports:
- 13306:3306
environment:
- MARIADB_ROOT_PASSWORD=************
- MARIADB_DATABASE=gogs
- MARIADB_USER=gogs
- MARIADB_PASSWORD=************
volumes:
- ./mariadb/data:/var/lib/mysql
- ./mariadb/my.cnf:/etc/mysql/conf.d/my.cnf
- ./mariadb/sql:/docker-entrypoint-initdb.d
sudo docker-compose up -d
sudo docker-compose ps
sudo docker-compose stop
https://qiita.com/wasanx25/items/d47caf37b79e855af95f
https://mebee.info/2020/08/05/post-15924/
データの引っ越し
- データベース
- gogs-repositories
- config
データベース
mysqldump -u git -p gogs_git > gogs.sql.bak
mysql -u gogs -p gogs --port=13306 < /home/adeno/gogs.sql.bak
gogs-repositories
data/gogs/data/gogs-repositoriesにコピー
config
[repository]
ROOT = /app/gogs/data/gogs-repositories
結局
gogs backup
を使わなかった。
初期設定でのデーターベース設定は以下を参考にした。
https://mebee.info/2020/08/05/post-15924/
ホスト名をgogs_mariadb_1にする
adeno@blackcore:/mnt/backuparea/gogs$ sudo docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------------------
gogs /app/gogs/docker/start.sh ... Up (healthy) 22/tcp, 0.0.0.0:3000-
>3000/tcp,:::3000->3000/tcp
gogs_mariadb_1 docker-entrypoint.sh mariadbd Up 0.0.0.0:13306->3306/tcp,:::13306-
>3306/tcp
rootで実行される
気になる。
rootで実行するし、作成されるファイルも所有者はroot
でもコンテナ内はgitになっている。
adeno@blackcore:/mnt/backuparea/gogs$ ls -l data/gogs/data/
合計 12
drwxr-xr-x 6 root root 4096 2月 6 12:34 gogs
drwxr-xr-x 7 root root 4096 2月 6 12:34 gogs-repositories
drwx------ 3 root root 4096 2月 6 12:34 sessions
sudo docker exec -it gogs /bin/bash
0f3d4c05ae00:/app/gogs# ls -l data/
total 12
drwxrwxr-x 6 git git 4096 Feb 5 15:59 gogs
drwxr-xr-x 7 git git 4096 Feb 5 15:59 gogs-repositories
drwx------ 4 git git 4096 Feb 6 03:35 sessions
https://qiita.com/yitakura731/items/36a2ba117ccbc8792aa7
気になる。
なにか方法があるのか
- rootless
- rootless + SELinux
- Podman
https://e-penguiner.com/rootless-docker-for-nonroot/
https://matsuand.github.io/docs.docker.jp.onthefly/engine/security/rootless/
https://matsuand.github.io/docs.docker.jp.onthefly/engine/security/userns-remap/
https://docs.docker.jp/desktop/install/linux-install.html#linux-install-file-sharing
docker rootlessを試してみる
いろいろ試行錯誤したのを一旦整理
まずは普通のインストール
https://docs.docker.com/engine/install/ubuntu/
以下の手順のみLinux Mintでは異なるので注意
3.Use the following command to set up the repository:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ lsb_release -cs
vanessa
UbuntuのOSバージョンを表示させるにはUBUNTU_CODENAMEが必要
$ cat /etc/os-release
NAME="Linux Mint"
VERSION="21 (Vanessa)"
ID=linuxmint
ID_LIKE="ubuntu debian"
PRETTY_NAME="Linux Mint 21"
VERSION_ID="21"
HOME_URL="https://www.linuxmint.com/"
SUPPORT_URL="https://forums.linuxmint.com/"
BUG_REPORT_URL="http://linuxmint-troubleshooting-guide.readthedocs.io/en/latest/"
PRIVACY_POLICY_URL="https://www.linuxmint.com/"
VERSION_CODENAME=vanessa
UBUNTU_CODENAME=jammy
なので
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
jammy stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
としちゃう。
動作確認
これで、普通モードの動作確認ができる
sudo docker run hello-world
rootlessモード
ユーザーを作る
- ユーザー:gogs_docker 1003
- グループ:gogs-rtls-docker 10099
サブ UID/サブ GIDの設定
$ cat /etc/subuid
gogs_docker:100000:65536
$ cat /etc/subgid
gogs_docker:100000:65536
インストール
https://matsuand.github.io/docs.docker.jp.onthefly/engine/security/rootless/
gogs_docker@blackcore:~$ dockerd-rootless-setuptool.sh install
[INFO] systemd not detected, dockerd-rootless.sh needs to be started manually:
PATH=/home/gogs_docker/bin:/sbin:/usr/sbin:$PATH dockerd-rootless.sh
[INFO] Creating CLI context "rootless"
Successfully created context "rootless"
[INFO] Use CLI context "rootless"
Current context is now "rootless"
Warning: DOCKER_HOST environment variable overrides the active context. To use "rootless", either set the global --context flag, or unset DOCKER_HOST environment variable.
[INFO] Make sure the following environment variables are set (or add them to ~/.bashrc):
# WARNING: systemd not found. You have to remove XDG_RUNTIME_DIR manually on every logout.
export XDG_RUNTIME_DIR=/home/gogs_docker/.docker/run
export PATH=/home/gogs_docker/bin:$PATH
Some applications may require the following environment variable too:
export DOCKER_HOST=unix:///home/gogs_docker/.docker/run/docker.sock
.bashrcに書くのを忘れない
export XDG_RUNTIME_DIR=/home/gogs_docker/.docker/run
export PATH=/home/gogs_docker/bin:$PATH
動作確認
gogs_docker@blackcore:~$ systemctl --user start docker
Failed to connect to bus: そのようなファイルやディレクトリはありません
gogs_docker@blackcore:~$ systemctl --user status
Failed to connect to bus: そのようなファイルやディレクトリはありません
あれ?
XDG_RUNTIME_DIR=/run/user/$(id -u gogs_docker) systemctl --user status
● blackcore
State: degraded
Jobs: 0 queued
Failed: 2 units
Since: Sun 2023-02-12 01:52:28 JST; 9h ago
CGroup: /user.slice/user-1003.slice/user@1003.service
<<略>>
XDG_RUNTIME_DIR=/run/user/$(id -u gogs_docker) systemctl --user start docker
Failed to start docker.service: Unit docker.service not found.
ほう。docker.serviceがないのか・・・。
docker.serviceを手動で作る
仕方がないので
.config/systemd/user/docker.service
を手動で作成した。
[Unit]
Description=Docker Application Container Engine (Rootless)
Documentation=https://docs.docker.com/go/rootless/
[Service]
Environment=PATH=/home/gogs_docker/bin:/sbin:/usr/sbin:/home/gogs_docker/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
ExecStart=/home/gogs_docker/bin/dockerd-rootless.sh
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
StartLimitBurst=3
StartLimitInterval=60s
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
Delegate=yes
Type=notify
NotifyAccess=all
KillMode=mixed
[Install]
WantedBy=default.target
今度こそ
まずはsudoできるユーザーで確認
adeno@blackcore:~$ sudo -u gogs_docker XDG_RUNTIME_DIR=/run/user/$(id -u gogs_docker) systemctl --user status
[sudo] adeno のパスワード:
● blackcore
State: running
Jobs: 0 queued
Failed: 0 units
Since: Sun 2023-02-12 12:56:38 JST; 8h ago
CGroup: /user.slice/user-1003.slice/user@1003.service
├─session.slice
│ └─pipewire.service
│ └─1188 /usr/bin/pipewire
├─app.slice
│ ├─docker.service
│ │ ├─16301 rootlesskit --net=slirp4netns --mtu=65520 --slirp4netns-sandbox=auto --slirp4netns-seccomp=auto --disable-host-loopback --port-driver=builtin>
│ │ ├─16310 /proc/self/exe --net=slirp4netns --mtu=65520 --slirp4netns-sandbox=auto --slirp4netns-seccomp=auto --disable-host-loopback --port-driver=buil>
│ │ ├─16328 slirp4netns --mtu 65520 -r 3 --disable-host-loopback --enable-sandbox --enable-seccomp 16310 tap0
│ │ ├─16336 dockerd
│ │ └─16363 containerd --config /run/user/1003/docker/containerd/containerd.toml --log-level info
│ └─dbus.service
│ └─1234 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
└─init.scope
├─1140 /lib/systemd/systemd --user
└─1149 (sd-pam)
sudo -u gogs_docker XDG_RUNTIME_DIR=/run/user/$(id -u gogs_docker) systemctl --user start docker
よし。
次に、dockerを実行したい一般ユーザーで確認
XDG_RUNTIME_DIR=/run/user/$(id -u gogs_docker) systemctl --user status
● blackcore
State: running
Jobs: 0 queued
Failed: 0 units
Since: Sun 2023-02-12 12:56:38 JST; 8h ago
CGroup: /user.slice/user-1003.slice/user@1003.service
├─session.slice
│ └─pipewire.service
│ └─1188 /usr/bin/pipewire
├─app.slice
│ ├─docker.service
│ │ ├─16301 rootlesskit --net=slirp4netns --mtu=65520 --slirp4netns-sandbox=auto --slirp4netns-seccomp=auto --disable-host-loopback --port-driver=builtin>
│ │ ├─16310 /proc/self/exe --net=slirp4netns --mtu=65520 --slirp4netns-sandbox=auto --slirp4netns-seccomp=auto --disable-host-loopback --port-driver=buil>
│ │ ├─16328 slirp4netns --mtu 65520 -r 3 --disable-host-loopback --enable-sandbox --enable-seccomp 16310 tap0
│ │ ├─16336 dockerd
│ │ └─16363 containerd --config /run/user/1003/docker/containerd/containerd.toml --log-level info
│ └─dbus.service
│ └─1234 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
└─init.scope
├─1140 /lib/systemd/systemd --user
└─1149 (sd-pam)
良いね。状態取れた。
サンプルを実行してみる
$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
よし。
gogs_docker@blackcore:/mnt/backuparea/gogs_rootless$ docker-compose up
gogs_rootless_mariadb_1 is up-to-date
Starting gogs ... done
Attaching to gogs_rootless_mariadb_1, gogs
<<略>>
OK gogs動いた!
自動起動
systemctl --user enable docker
sudo loginctl enable-linger $(whoami)
XDG_RUNTIME_DIR=/run/user/$(id -u gogs_docker) systemctl --user enable docker
Created symlink /home/gogs_docker/.config/systemd/user/default.target.wants/docker.service → /home/gogs_docker/.config/systemd/user/docker.service.
が、再起動後にPSで実行中のコンテナが見れなくなってしまった。
gogs_docker@blackcore:/mnt/backuparea/gogs_rootless$ docker ps -a
Cannot connect to the Docker daemon at unix:///home/gogs_docker/.docker/run/docker.sock. Is the docker daemon running?
sockの場所を明示すると動いた
docker -H unix:///run/user/1003/docker.sock ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c6a2687906f9 gogs/gogs:latest "/app/gogs/docker/st…" 3 hours ago Up 3 hours (healthy) 22/tcp, 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp gogs
2b74ddf55d44 mariadb:latest "docker-entrypoint.s…" 3 hours ago Up 3 hours 0.0.0.0:13306->3306/tcp, :::13306->3306/tcp gogs_rootless_mariadb_1
$ docker-compose ps
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1037, in _send_output
self.send(msg)
File "/usr/lib/python3.10/http/client.py", line 975, in send
self.connect()
File "/usr/lib/python3/dist-packages/docker/transport/unixconn.py", line 30, in connect
sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 532, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3/dist-packages/six.py", line 718, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1037, in _send_output
self.send(msg)
File "/usr/lib/python3.10/http/client.py", line 975, in send
self.connect()
File "/usr/lib/python3/dist-packages/docker/transport/unixconn.py", line 30, in connect
sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/docker/api/client.py", line 214, in _retrieve_server_version
return self.version(api_version=False)["ApiVersion"]
File "/usr/lib/python3/dist-packages/docker/api/daemon.py", line 181, in version
return self._result(self._get(url), json=True)
File "/usr/lib/python3/dist-packages/docker/utils/decorators.py", line 46, in inner
return f(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/docker/api/client.py", line 237, in _get
return self.get(url, **self._set_request_timeout(kwargs))
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 33, in <module>
sys.exit(load_entry_point('docker-compose==1.29.2', 'console_scripts', 'docker-compose')())
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 81, in main
command_func()
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 200, in perform_command
project = project_from_options('.', options)
File "/usr/lib/python3/dist-packages/compose/cli/command.py", line 60, in project_from_options
return get_project(
File "/usr/lib/python3/dist-packages/compose/cli/command.py", line 152, in get_project
client = get_client(
File "/usr/lib/python3/dist-packages/compose/cli/docker_client.py", line 41, in get_client
client = docker_client(
File "/usr/lib/python3/dist-packages/compose/cli/docker_client.py", line 170, in docker_client
client = APIClient(use_ssh_client=not use_paramiko_ssh, **kwargs)
File "/usr/lib/python3/dist-packages/docker/api/client.py", line 197, in __init__
self._version = self._retrieve_server_version()
File "/usr/lib/python3/dist-packages/docker/api/client.py", line 221, in _retrieve_server_version
raise DockerException(
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 153, in apport_excepthook
with os.fdopen(os.open(pr_filename,
FileNotFoundError: [Errno 2] No such file or directory: '/var/crash/_usr_bin_docker-compose.1003.crash'
Original exception was:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1037, in _send_output
self.send(msg)
File "/usr/lib/python3.10/http/client.py", line 975, in send
self.connect()
File "/usr/lib/python3/dist-packages/docker/transport/unixconn.py", line 30, in connect
sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 532, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3/dist-packages/six.py", line 718, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1037, in _send_output
self.send(msg)
File "/usr/lib/python3.10/http/client.py", line 975, in send
self.connect()
File "/usr/lib/python3/dist-packages/docker/transport/unixconn.py", line 30, in connect
sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/docker/api/client.py", line 214, in _retrieve_server_version
return self.version(api_version=False)["ApiVersion"]
File "/usr/lib/python3/dist-packages/docker/api/daemon.py", line 181, in version
return self._result(self._get(url), json=True)
File "/usr/lib/python3/dist-packages/docker/utils/decorators.py", line 46, in inner
return f(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/docker/api/client.py", line 237, in _get
return self.get(url, **self._set_request_timeout(kwargs))
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 33, in <module>
sys.exit(load_entry_point('docker-compose==1.29.2', 'console_scripts', 'docker-compose')())
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 81, in main
command_func()
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 200, in perform_command
project = project_from_options('.', options)
File "/usr/lib/python3/dist-packages/compose/cli/command.py", line 60, in project_from_options
return get_project(
File "/usr/lib/python3/dist-packages/compose/cli/command.py", line 152, in get_project
client = get_client(
File "/usr/lib/python3/dist-packages/compose/cli/docker_client.py", line 41, in get_client
client = docker_client(
File "/usr/lib/python3/dist-packages/compose/cli/docker_client.py", line 170, in docker_client
client = APIClient(use_ssh_client=not use_paramiko_ssh, **kwargs)
File "/usr/lib/python3/dist-packages/docker/api/client.py", line 197, in __init__
self._version = self._retrieve_server_version()
File "/usr/lib/python3/dist-packages/docker/api/client.py", line 221, in _retrieve_server_version
raise DockerException(
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
こちらも同様
docker-compose -H unix:///run/user/1003/docker.sock ps
Name Command State Ports
--------------------------------------------------------------------------------------------------------------------------
gogs /app/gogs/docker/start.sh ... Up (healthy) 22/tcp, 0.0.0.0:3000->3000/tcp,:::3000->3000/tcp
gogs_rootless_mariadb_1 docker-entrypoint.sh mariadbd Up 0.0.0.0:13306->3306/tcp,:::13306->3306/tcp
.bashrcに書いた
export XDG_RUNTIME_DIR=/home/gogs_docker/.docker/run
が余計だったのかな・・・。
これをコメントアウトして試してみる
これで
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock
docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------------------------------
gogs /app/gogs/docker/start.sh ... Up (healthy) 22/tcp, 0.0.0.0:3000->3000/tcp,:::3000->3000/tcp
gogs_rootless_mariadb_1 docker-entrypoint.sh mariadbd Up 0.0.0.0:13306->3306/tcp,:::13306->3306/tcp
今度こそ大丈夫そう。
改めてデータの引っ越しをする。
データの引っ越し
- データベース
- gogs-repositories
- config
データベース
mysqldump -u git -p gogs_git > gogs.sql.bak
mysql -u gogs -p gogs --port=13306 < /home/adeno/gogs.sql.bak
gogs-repositories
data/gogs/data/gogs-repositoriesにコピー
データの所有者を100999(コンテナ内のgit(10000)相当)にしておく
config
[repository]
ROOT = /app/gogs/data/gogs-repositories
ホスト名をgogs_mariadb_1にする
これでOKOK
更新ができない
なぜか、もともとの/home/git/gogs-repositoriesを参照しようとする。
困ったので、最終手段でシンボリックリンクを張った。
gogs_docker@blackcore:/mnt/backuparea/gogs$ docker exec -it gogs /bin/bash
c6a2687906f9:/home/git/gogs-repositories# mkdir -p /home/git/gogs/gogs
6a2687906f9:/home/git/gogs-repositories# cd /home/git/gogs/gogs/
c6a2687906f9:/home/git/gogs/gogs# ln -s /app/gogs/data/gogs-repositories/gogs-repositories gogs-repositories
c6a2687906f9:/home/git/gogs/gogs# ls -l
total 0
lrwxrwxrwx 1 root root 50 Feb 15 16:18 gogs-repositories -> /app/gogs/data/gogs-repositories/gogs-repositories