Docker提交创建的图像和ENTRYPOINT [英] Docker Commit Created Images and ENTRYPOINT
问题描述
如果您确保在Dockerfile中指定的原始CMD仍然设置为在 docker run
上运行,当您通过 docker commit进行更改
?
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:
- 使用Dockerfile创建图像
- 使用
-ti --entrypoint / bin / bash
在某些时候进行一些修改 - 在容器内进行更改并运行
docker commit
创建新的图像,使用新的标签 -
- 当运行新图像时,原始Dockerfile的原始CMD条目不再运行
- 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?
推荐答案
您将创建一个Docker文件来设置 CMD
或 ENTRYPOINT
。只需将Dockerfile放在由 docker commit
返回的图像ID上。例如,给定:
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
我可以创建一个如下所示的Docker文件:
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
说,你最好操作过程可能是不是在容器中进行更改,然后使用Docker commit;如果您只是依靠Dockerfile来实现必要的更改,那么最终会有更多可审核的变更。
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.
这篇关于Docker提交创建的图像和ENTRYPOINT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!