0
0

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.

Vagrant仮想化環境でDocker Composeのボリューム永続化しようとしてハマったこと

Last updated at Posted at 2021-04-28

Vagrant 仮想化環境で Docker Compose を使った際にちょっとハマったのでメモ。

なにがあったのか

仮想化ホストOS:Windows10
仮想化ソフト:VirtualBox+Vagrant
ゲストOS:Ubuntu20.4

コンテナ:
https-portal
nginx
mysql

以上のような構成で docker-compose up しても、https-portal と mysql のステータスが Restarting を繰り返しててうまくいかなかった。

なにがだめだったのか

結論から言うと、https-portal と mysql の永続化ボリュームを、Vagrant の共有ディレクトリ内に作成していたためでした。

docker-compose.yml
  mysql:
    (中略)
    volumes:
      - ./build/mysql/initdb:/docker-entrypoint-initdb.d
      - ./db:/var/lib/mysql
  https-portal:
    (中略)
    volumes:
      - ./cert:/var/lib/https-portal

docker-compose.yml のあるフォルダは Vagrant と共有していたので、これだと db フォルダと cert フォルダの場所が Vagrant で共有しているフォルダ内にできてしまいます。
image.png
https-portal の証明書ファイルなどのオーナーが vagrant になってしまうのでだめみたいでした。

どう解決したか

db フォルダと cert フォルダの場所を Vagrant で共有しているフォルダ外になるようにしたらうまくいきました。

docker-compose.yml
  mysql:
    (中略)
    volumes:
      - ./build/mysql/initdb:/docker-entrypoint-initdb.d
      - ../db:/var/lib/mysql
  https-portal:
    (中略)
    volumes:
      - ../cert:/var/lib/https-portal

以下の図のように共有フォルダ外に作成されました。
image.png
Vagrantfile の config.vm.synced_folder に mount_options を指定することでも解決できるのかもしれませんが、db フォルダと cert フォルダは Windows でいじりたいものではなかったので共有しないという選択を取りました。今後、アプリを入れる www フォルダで権限絡みの問題が発生したときには mount_options を検討してみようと思います。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?