Closed sescobb27 closed 6 years ago
While trying to bind-mount a host directory to a container work I tried to make it work using the official docker client without success, here are the steps i used
# https://github.com/docker/docker-py
# python2.7
# https://docker-py.readthedocs.io/en/1.4.0/volumes/
from docker import Client
c = Client(base_url='unix://var/run/docker.sock')
host_config = c.create_host_config(binds=['/Users/kiro/test:/data'])
container_id = c.create_container('busybox:1.29', 'ls /data', volumes=['/data'], host_config=host_config)
c.commit(container_id)
Then with the ImageId
returned from c.commit(container_id)
i ran it with docker run -it ImageId /bin/bash
and then run ls /data
but the directory is empty and it shouldn't be empty
it seems we can create a container with the mounted directory but we can't create an image with that mounted directory. https://github.com/moby/moby/issues/6999
NOTE: yes, that seems to be the issue. the steps to reproduce are the same as the steps above but instead of commiting the container and running it, I just ran docker start -ai ContainerId
It may be the case that having mounted that directory - and run a command, and generated an image, you will need to mount that directory when you create a container from that image in order to run subsequent commands. If it were a (pseudo) dockerfile/build it would look something like this.
MOUNT /foo
(interpret the mount command)RUN echo "bar" > /foo/bar
(execute command, stop container, create image 1)RUN cat /foo/bar > /foo/baz
(you create a container from image 1 with /foo
mount, execute command, stop container, and create image 2)RUN echo bop > /foo/bop
(you create a container from image 2 with /foo
mount, execute command, stop container, and create image 3)+1
closing this PR in favor of https://github.com/sescobb27/ex_docker_build
** Usage