Skip to content

Instantly share code, notes, and snippets.

@dnephin
Created January 27, 2015 03:53
Show Gist options
  • Save dnephin/083a1052b8293a5b46a4 to your computer and use it in GitHub Desktop.
Save dnephin/083a1052b8293a5b46a4 to your computer and use it in GitHub Desktop.
Docker volumes set using bind at start time
FROM busybox:latest
RUN mkdir /data
RUN touch /data/file
VOLUME /data
CMD echo
import docker
def run():
client = docker.Client()
client.build('.', tag='example_volumes', stream=False)
container = client.create_container('example_volumes')
client.start(container)
client.wait(container)
volumes = client.inspect_container(container)['Volumes']
print volumes
# Now start another container that tries to use this volume
container = client.create_container('example_volumes')
client.start(container, binds={
volumes['/data']: {'bind': '/data', 'ro': False},
})
client.wait(container)
print client.inspect_container(container)['Volumes']
if __name__ == "__main__":
run()
#!/bin/bash
virtualenv venv
source venv/bin/activate
pip install docker-py
python repo.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment