LoginSignup
5
6

More than 5 years have passed since last update.

Windows7 で Docker Toolbox 使って立てた Nginx コンテナに default.conf をマウントしたい

Last updated at Posted at 2019-03-14

Windows 7 で Docker コンテナにホストマシンにあるファイルをマウントしたいけどできなくて、調べた結果どういうことか理解できてマウントできたからメモ。

qiita_20190314_1_1.PNG

docker-compose.yml は↓の通り。

services:
  web:
    image: nginx:1.15.9-alpine
    volumes:
      - ./web/default.conf:/etc/nginx/conf.d/default.conf

コンテナ起動。

$ docker-compose up -d
ERROR: for docker_web_1  Cannot start service web: OCI runtime create failed: container_linux.go:344: starting container process caused "process_linux
.go:424: container init caused \"rootfs_linux.go:58: mounting \\\"/c/docker/web/default.conf\\\" to rootfs \\\"/mnt/sda1/var/lib/docker/overlay2/
4e5408b7aa6822b12405a15c1531a535e5008301ba684d80d6d3c9e9b5d75029/merged\\\" at \\\"/mnt/sda1/var/lib/docker/overlay2/4e5408b7aa6822b12405a15
c1531a535e5008301ba684d80d6d3c9e9b5d75029/merged/etc/nginx/conf.d/default.conf\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount
 a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

ディレクトリをファイルにマウントしようとしてんじゃねーの?と怒られる。
めっちゃファイルだわ。
ちなみにこの現象、Mac では発生しない。

ググっても Docker for Windows ネタばかり。(今どき Windows 7 なんて誰も使わry)

COMPOSE_CONVERT_WINDOWS_PATHS を設定しろとか、共有フォルダにしろとか書いてあるけどよく分からん。
と思ってちゃんと調べたら解決したので備忘メモ。

そもそも Docker が動くのは VM(Virtual Box)上。
Docker がマウントしようとしてるのは VM 内にあるファイル(フォルダ)。
つまりこういうこと。

qiita_20190314_1_2.PNG

この辺を理解している賢い人がこう言っている。
「VMにフォルダを共有しろ」

↓このページを参考に共有設定をする。
Docker toolbox on windows マウント:Dockerコンテナの中でホストのフォルダを見たい

VM に入ってマウントされていることを確認する。(共有したのは C:\docker)

$ docker-machine ssh default 'ls /c/docker'

Docker を起動してファイルがマウントされていることを確認する。

$ docker-compose up -d
$ docker exec -it [コンテナ名] cat /etc/nginx/conf.d/default.conf

おわり。

5
6
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
5
6