How do you ensure that the original CMD specified in your Dockerfile is still set to run on docker run
, when you make changes via docker commit
?
Here's the sequence of events, to make it a little clearer:
- Create image with Dockerfile
- Run container from image with
-ti --entrypoint /bin/bash
at some point afterwards to make some changes - Make changes inside container and run
docker commit
to create new image, with new tag - When the new image is run, the original CMD entry from the original Dockerfile is no longer run
So I'm asking; how do you reset the CMD from the Dockerfile again on a committed image?
Current Docker versions (I'm on 1.11.1) provide a
--change
option that allow in-line manipulation of the image at commit time, as in:CMD
is also supported as are a few others. See manpage for more details and examples.You would create a Dockerfile to set the
CMD
orENTRYPOINT
. Simply base the Dockerfile on the image id returned bydocker commit
. For example, given this:I could create a Dockerfile that looked like this:
And then use that to build a new image:
That said, your best course of action is probably to not make changes in the container and then use Docker commit; you end up with a much more auditable set of changes if you just rely on the Dockerfile to implement the necessary changes in the first place.