Skip to content

Instantly share code, notes, and snippets.

@dnephin
Last active August 29, 2015 14:14
Show Gist options
  • Save dnephin/e584a7741a514d631632 to your computer and use it in GitHub Desktop.
Save dnephin/e584a7741a514d631632 to your computer and use it in GitHub Desktop.
Docker override volumes in 1.4.1
Using
docker inspect -f '
{{ .Config.Volumes }}
{{ .Volumes }}
{{ .HostConfig.Binds }}' <container_name>
The container from the example looks correct (the volume is actually the path set by the bind)
map[/data:map[]]
map[/data:/var/lib/docker/vfs/dir/5ae3918f38168bb805ea3d1ffd67665a63c2d251f4e64fb9f33fef9e94bef2da]
[/var/lib/docker/vfs/dir/5ae3918f38168bb805ea3d1ffd67665a63c2d251f4e64fb9f33fef9e94bef2da:/data:rw]
But from the fig test case, its wrong
map[/data:map[]]
map[/data:/var/lib/docker/vfs/dir/730dffbbf9745a9dda9ad7ed181cd28ad4ed8b1e021481f9427d1b0aabe1c7fc]
[/var/lib/docker/vfs/dir/a79ef82a4e1691f892c9c383139fce009dce439d51b0faff464aed9029732e7e:/data:rw]
#!/bin/bash
set -eu
docker rm volume_example_1 volume_example_2
# Step 1: Create a container with a data volume
cat << EOF > Dockerfile
FROM busybox:latest
RUN mkdir /data
RUN touch /data/file
VOLUME /data
CMD echo
EOF
docker build -t volume_example .
docker run --name volume_example_1 -ti volume_example
volume_path="$(docker inspect -f '{{index .Volumes "/data"}}' volume_example_1)"
echo "Container 1, /data path: $volume_path"
# Step 2: Create another container which tries to use that volume
docker run --name volume_example_2 -v $volume_path:/data:rw volume_example
new_path="$(docker inspect -f '{{index .Volumes "/data"}}' volume_example_2)"
echo "Container 2, /data path: $new_path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment