1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Ubuntu 20.04でdocker run時にvolumeを設定したら想定外のパスにvolumeが作成されていた

Last updated at Posted at 2020-12-10

いきなり結論

docker run時に、volumeを/tmp配下に設定したところ/tmp配下には作成されず、
代わりに/tmp/snap.docker/tmp配下にvolume用のディレクトリが作成されました。

当方、めんどくさがってUbuntuインストール時のFeatured Server Snapsにて
dockerにチェックを入れていました。

そのせいで、snap(Snappyの方が正式名称?)パッケージで提供されるdockerが
インストールされてしまったようです。

snapパッケージのため、Ubuntuのファイルシステムへ直接ファイルを置くことはせず、
snapによってマッピングされた先にvolumeが作成されるみたいです。

環境

ソフトウェア バージョン
Ubuntu 20.04.1 LTS Server
  • その他
  • x86-64bit環境
  • Ubuntuインストール時のFeatured Server Snapsでdockerにチェックを入れた

実行したdocker runのコマンドと、実行後のvolumeの作成先

# docker run --detach \
  --publish 40443:443 --publish 40080:80 --publish 40022:22 \
  --name test_gitlab \
  --restart always \
  --volume /tmp/gitlab/config:/etc/gitlab \
  --volume /tmp/gitlab/logs:/var/log/gitlab \
  --volume /tmp/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce:latest

ボリュームに「/tmp/gitlab/config」「/tmp/gitlab/logs」「/tmp/gitlab/data」を
指定しているので、/tmp配下にgitlabディレクトリが作成されるはずと思ってみてみると。。。

# ls -lt /tmp
total 24
drwx------ 3 root root 4096 Dec 10 16:20 snap.lxd
drwx------ 3 root root 4096 Dec 10 16:20 snap.docker
drwx------ 3 root root 4096 Dec 10 16:20 systemd-private-35a61383cfc041f8bf4ccb7c92a2b205-systemd-logind.service-O4Ix6i
drwx------ 3 root root 4096 Dec 10 16:20 systemd-private-35a61383cfc041f8bf4ccb7c92a2b205-systemd-resolved.service-nHhtTi
drwx------ 2 root root 4096 Dec 10 16:20 vmware-root_842-2688554003
drwx------ 3 root root 4096 Dec 10 16:20 systemd-private-35a61383cfc041f8bf4ccb7c92a2b205-systemd-timesyncd.service-rkNQXi

上記の通り、gitlabディレクトリは存在しませんでした。
じゃあ「/tmp/gitlab/config」「/tmp/gitlab/logs」「/tmp/gitlab/data」は
どこに作成されたのかというと。。。

「いきなり結論」の章で書いた通り「/tmp/snap.docker/tmp」配下に作成されていました。

# ls -lt /tmp/snap.docker/tmp/gitlab/
total 12
drwxr-xr-x 20 root root 4096 Dec 10 16:56 data
drwxr-xr-x 20 root root 4096 Dec 10 16:55 logs
drwxrwxr-x  3 root root 4096 Dec 10 16:52 config

他のディレクトリを指定したらどうなるか?

例えば、volumeに/tmpではなく/srvを指定したらどうなるでしょうか?
(gitlabのdocker runコマンドって、公式HPにvolumeは/srv使えって書いてあるんですよね。)

# docker run --detach \
>   --publish 40443:443 --publish 40080:80 --publish 40022:22 \
>   --name test_gitlab \
>   --restart always \
>   --volume /srv/gitlab/config:/etc/gitlab \
>   --volume /srv/gitlab/logs:/var/log/gitlab \
>   --volume /srv/gitlab/data:/var/opt/gitlab \
>   gitlab/gitlab-ce:latest
81cc3ce3e813c482d7e9b8e4253ed433b28e51f133fa9df012adaef462f5dc5a
docker: Error response from daemon: error while creating mount source path '/srv/gitlab/data': mkdir /srv/gitlab: read-only file system.

エラーになります。
推測ですが、snapにて/srvへのマッピング先ディレクトリが指定されていないため
ディレクトリを作成することができずエラーになるようです。

課題

じゃぁUbuntu 20.04LTS Serverをインストール時ではなく、インストール後にaptで
docker入れたらどうなるか?
時間があるときに試してみます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?