Docker Community Forums

Share and learn in the Docker community.

Volume still in new image

(Xwtqin) #1

I have run a container named container1 using the following commands:$ **docker run --name container1 -itd -v /home busybox /bin/sh. I attached to it and added a file named file1 in /home directory, and then commit it as a new image named busybox_new by:$ docker commit container1 busybox_new. Later I run a new container using commands:$ docker run --name container2 -itd busybox_new /bin/sh,and attached to it seeing there is nothing in /home as I expected. However, when I created a new file named file2 in /home directory in container2 and commit it as busybox_new2 image and run a new container named container3 using busybox_new2, there is still nothing in /home where I have created a file named file2 in container2. I can see a volume /home in container3 when inspecting it although I didn’t run the container3 using -v parameter. How can I remove the volume in busybox_new2 imge? And I am wondering why it should create a volume when running new container through new image without -v parameter ?

(David Maze) #2

I don’t have a solid answer to your question, but I’d advise you to stop using docker commit. Eventually you’re going to wish you had a single file that listed out everything that went into the image and what commands you manually ran, so that you can apply some update to it. That file might look like:

FROM busybox
COPY foo /home
VOLUME /home

Name that file Dockerfile, then run docker build -t busybox_new, and you’ve recreated the first stop of your sequence.