Docker Commit Created Images and ENTRYPOINT

前端 未结 2 416
夕颜
夕颜 2020-12-25 11:30

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?

相关标签:
2条回答
  • 2020-12-25 12:02

    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.

    0 讨论(0)
  • 2020-12-25 12:20

    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.

    0 讨论(0)
提交回复
热议问题