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:
-ti --entrypoint /bin/bash
at some point afterwards to make some changesdocker commit
to create new image, with new tagSo I'm asking; how do you reset the CMD from the Dockerfile again on a committed image?
Any Docker image must have an ENTRYPOINT or CMD declaration for a container to start. Though the ENTRYPOINT and CMD instructions may seem similar at first glance, there are fundamental differences in how they build container images. (This is part of our Docker Guide.
Description. It can be useful to commit a container's file changes or settings into a new image. This allows you to debug a container by running an interactive shell, or to export a working dataset to another server. Generally, it is better to use Dockerfiles to manage your images in a documented and maintainable way.
You can run docker commit (docs) to save the container to an image, then push that image with a new tag to the registry. Show activity on this post. This can be easily done by using "docker commit".
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With