Skip to content

Instantly share code, notes, and snippets.

@r4um
Last active January 13, 2016 09:02
Show Gist options
  • Save r4um/54cc40b2686fd8ccecdd to your computer and use it in GitHub Desktop.
Save r4um/54cc40b2686fd8ccecdd to your computer and use it in GitHub Desktop.
docker VOUME foo
‣ tree
.
├── Dockerfile
└── foo
    └── bar
        └── gendata

2 directories, 2 files
‣ cat foo/bar/gendata
#!/bin/bash
set -x
bash -c 'echo foo > /foo/bar/G'
FROM ubuntu
VOLUME /foo/bar
COPY . /
RUN /foo/bar/gendata
WORKDIR /foo/bar
RUN if [ -f "/foo/bar/G" ]; then echo "Yes!"; else echo "No!"; fi
‣ docker build --no-cache .
Sending build context to Docker daemon 4.096 kB
Step 1 : FROM ubuntu
 ---> c4bea91afef3
Step 2 : VOLUME /foo/bar
 ---> Running in 8ad82bbd02ef
 ---> 4c4d2dfaa48c
Removing intermediate container 8ad82bbd02ef
Step 3 : COPY . /
 ---> cf9110af49d8
Removing intermediate container 08caf8b41b0e
Step 4 : RUN /foo/bar/gendata
 ---> Running in 2ab934d4bf2a
+ bash -c 'echo foo > /foo/bar/G'
 ---> f8d296d678a6
Removing intermediate container 2ab934d4bf2a
Step 5 : WORKDIR /foo/bar
 ---> Running in 15184db7f136
 ---> 1cf05639dccf
Removing intermediate container 15184db7f136
Step 6 : RUN if [ -f "/foo/bar/G" ]; then echo "Yes!"; else echo "No!"; fi
 ---> Running in 026f0cc7dabf
No!
 ---> 1d1036bd6499
Removing intermediate container 026f0cc7dabf
Successfully built 1d1036bd6499

Specify a mount

‣ cat Dockerfile
FROM ubuntu
VOLUME /foo/bar:/tmp
COPY . /
RUN /foo/bar/gendata
WORKDIR /foo/bar
RUN if [ -f "/foo/bar/G" ]; then echo "Yes!"; else echo "No!"; fi

Works

‣ docker build --no-cache .
Sending build context to Docker daemon 4.096 kB
Step 1 : FROM ubuntu
 ---> c4bea91afef3
Step 2 : VOLUME /foo/bar:/tmp
 ---> Running in c81615a83889
 ---> 0a885965f21e
Removing intermediate container c81615a83889
Step 3 : COPY . /
 ---> 84c5a1da3047
Removing intermediate container cdfb0c16872b
Step 4 : RUN /foo/bar/gendata
 ---> Running in 03ac6a7f4307
+ bash -c 'echo foo > /foo/bar/G'
 ---> 079121b1768b
Removing intermediate container 03ac6a7f4307
Step 5 : WORKDIR /foo/bar
 ---> Running in 1e2a68bd2c9f
 ---> b44507af8b75
Removing intermediate container 1e2a68bd2c9f
Step 6 : RUN if [ -f "/foo/bar/G" ]; then echo "Yes!"; else echo "No!"; fi
 ---> Running in f59ae45e14b5
Yes!
 ---> 7909df2d58a0
Removing intermediate container f59ae45e14b5
Successfully built 7909df2d58a0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment