Skip to content

Instantly share code, notes, and snippets.

@mapk0y
Last active November 2, 2016 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapk0y/3f36620690c11a854e507ce195a1dc7d to your computer and use it in GitHub Desktop.
Save mapk0y/3f36620690c11a854e507ce195a1dc7d to your computer and use it in GitHub Desktop.
docker-compose の volumes について確認

バージョン

[mapk0y@kona:~]$ docker-compose --version
docker-compose version 1.8.1, build 878cff1
[mapk0y@kona:~]$ docker version
Client:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   6b644ec
 Built:        Wed Oct 26 21:39:14 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   6b644ec
 Built:        Wed Oct 26 21:39:14 2016
 OS/Arch:      linux/amd64

v1 format での記述

[mapk0y@kona:~]$ cat docker-compose.yml
deb:
    image: debian
    volumes:
        - ./cache:/tmp/cache
    command: sh -c "echo foo | tee /tmp/cache/foo"

[mapk0y@kona:~]$ docker-compose -f docker-compose.yml up
Creating volumestest_deb_1
Attaching to volumestest_deb_1
deb_1  | foo
volumestest_deb_1 exited with code 0
[mapk0y@kona:~]$ cat cache/foo && rm -vf cache/foo
foo
removed ‘cache/foo’
[mapk0y@kona:~]$ docker-compose -f docker-compose.yml down
Removing volumestest_deb_1 ... done

v2 format での記述

[mapk0y@kona:~]$ cat docker-compose-v2.yml
version: '2'

services:
    deb:
        image: debian
        volumes:
            - ./cache:/tmp/cache
        command: sh -c "echo foo | tee /tmp/cache/foo"

[mapk0y@kona:~]$ docker-compose -f docker-compose-v2.yml up
Creating network "volumestest_default" with the default driver
Creating volumestest_deb_1
Attaching to volumestest_deb_1
deb_1  | foo
volumestest_deb_1 exited with code 0
[mapk0y@kona:~]$ cat cache/foo && rm -vf cache/foo
foo
removed ‘cache/foo’
[mapk0y@kona:~]$ docker-compose -f docker-compose-v2.yml down
Removing volumestest_deb_1 ... done
Removing network volumestest_default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment