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
?
You would create a Dockerfile to set the CMD
or ENTRYPOINT
. Simply base the Dockerfile on the image id returned by docker commit
. For example, given this:
$ docker commit $(docker ps -lq)
69e9c08825508ec780efc86268a05ffdf4edae0999a2424dbe36cb04c2a15d6b
I could create a Dockerfile that looked like this:
FROM 69e9c08825508ec780efc86268a05ffdf4edae0999a2424dbe36cb04c2a15d6b
CMD ["/bin/bash"]
And then use that to build a new image:
$ docker build .
Step 0 : FROM 69e9c08825508ec780efc86268a05ffdf4edae0999a2424dbe36cb04c2a15d6b
---> 69e9c0882550
Step 1 : CMD /bin/bash
---> Running in f886c783551d
---> 13a0f8ea5cc5
Removing intermediate container f886c783551d
Successfully built 13a0f8ea5cc5
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.
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:
docker commit --change='ENTRYPOINT ["myEntryPoint.sh"]' $(docker ps -lq)
CMD
is also supported as are a few others. See manpage for more details and examples.