自分用のメモ
volumes_from
を使いたいときのdocker-compose.yml
リファレンスに書いてあることを書いただけ。
- アクセス権は省略すると
rw
-
/test1
に作ったファイルはコンテナcにのみ存在- コンテナcを消したらファイルも消える
-
/test2
に作ったファイルはdocker-compose.yml
と同階層に存在- コンテナcを消してもファイルは消えない
docker-compose.yml
version: "2"
services:
a:
image: alpine:latest
tty: true
volumes_from:
- d
b:
image: alpine:latest
tty: true
volumes_from:
- d:rw
c:
image: alpine:latest
tty: true
volumes_from:
- d:ro
d:
image: alpine:latest
tty: true
volumes:
- /test1
- .:/test2
アクセス権の確認結果
コンテナcからは書き込めないことを確認
$ docker-compose exec a ash
/ # touch test1/a1
/ # touch test2/a2
$ docker-compose exec b ash
/ # touch test1/b1
/ # touch test2/b2
$ docker-compose exec c ash
/ # touch test1/c1
touch: test1/c1: Read-only file system
/ # touch test2/c2
touch: test2/c2: Read-only file system
コンテナdの中身を確認すると
test1
と test2
にそれぞれ他のコンテナで作ったファイルが存在している。
$ docker-compose exec d ash
/ # ls -la /test1
total 8
drwxr-xr-x 2 root root 4096 Apr 8 12:25 .
drwxr-xr-x 1 root root 4096 Apr 8 12:22 ..
-rw-r--r-- 1 root root 0 Apr 8 12:25 a1
-rw-r--r-- 1 root root 0 Apr 8 12:25 b1
/ # ls -la /test2
total 8
drwxr-xr-x 5 root root 160 Apr 8 12:26 .
drwxr-xr-x 1 root root 4096 Apr 8 12:22 ..
-rw-r--r-- 1 root root 0 Apr 8 12:25 a2
-rw-r--r-- 1 root root 0 Apr 8 12:26 b2
-rw-r--r-- 1 root root 339 Apr 8 12:22 docker-compose.yml
Mac上のdocker-compose.ymlと同階層を確認するとtest2
に作ったファイルが存在している。
$ ls -la
total 8
drwxr-xr-x 5 sakuraba staff 160 4 8 21:26 .
drwxr-xr-x 7 sakuraba staff 224 4 8 20:50 ..
-rw-r--r-- 1 sakuraba staff 0 4 8 21:25 a2
-rw-r--r-- 1 sakuraba staff 0 4 8 21:26 b2
-rw-r--r-- 1 sakuraba staff 339 4 8 21:22 docker-compose.yml