Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define docker commit message in Dockerfile

Using Dockerfile (docker build) is an alternative for doing docker commit by hand. By using docker commit, there is an option named --message, which can be used to define commit messages. Commit messages are displayed in docker history in a dedicated column called COMMENT. My question is: how to define docker commit message in a Dockerfile?


2 Answers

It is well explained in the official docs here, here is how you do it:

First, commit a container to a image:

$ docker commit --message "Foo bar" 94bde3da7ffa dockertestcommess

Then, tag the image to fit the registry address:

$ docker tag dockertestcommess spekulant/dockertestcommess

And finally push the commited image:

$ docker push spekulant/dockertestcommess

And my docker history shows the message I commited:

$ docker history spekulant/dockertestcommess
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
d3c3f4e85723        7 minutes ago       /bin/sh -c cat helloworld.txt                   0B                  Foo bar
fec5f399e907        3 days ago          /bin/sh -c #(nop)  CMD ["/bin/sh" "-c" "cat …   0B
0f0405202b75        3 days ago          /bin/sh -c #(nop) COPY file:17e1650f32b894fc…   8B
3fd9065eaf02        3 months ago        /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B
<missing>           3 months ago        /bin/sh -c #(nop) ADD file:093f0723fa46f6cdb…   4.15MB
like image 51
trust512 Avatar answered Oct 19 '25 10:10

trust512


With a Dockerfile and docker build you create a completely new image. Therefore you do not have any changes that can be commented with a message. It is not possible to define a commit message in a Dockerfile.

As the docs point out docker commit is more useful for debugging purposes. To create a new image, docker build is recommended: https://docs.docker.com/engine/reference/commandline/commit/#extended-description

This makes sense, as committed images are hard to reproduce, with only a commit message as a hint on the changes. Using only a Dockerfile always leads to a reproducable build.

like image 22
mbuechmann Avatar answered Oct 19 '25 08:10

mbuechmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!