Is it good practice to commit docker container frequently?
Asked Answered
H

1

9

I'm using WebSphere Liberty inside. As WebSphere Liberty requires frequent xml editing, which is impossible with Dockerfile commands. I have to docker-commit the container from time to time, for others to make use of my images.

The command is like:

docker commit -m "updated sa1" -a "Song" $id company/wlp:v0.1

Colleges are doing similar things to the image, they continue to docker commit the container several times every day.

One day we're going to deploy the image on production.

Q1: Is the practice of frequent docker-committing advised?

Q2: Does it leave any potential problem behind?

Q3: Does it create an extra layer? I read the docker-commit document, which didn't mention if it creates another layer, I assume it means no.

Horsetail answered 9/8, 2018 at 8:7 Comment(0)
H
10

I wouldn't use docker commit,

It seems like a really good idea but you can't reproduce the image at will like you can with a Dockerfile and you can't change the base image once this is done either, so makes it very hard to commit say for example a security patch to the underlying os base image.

If you go the full Dockerfile approach you can re-run docker build and you'll get the same image again. And you are able to change the base image.

So my rule of thumb is if you are creating a temporary tool and you don't care about reuse or reproducing the image at will then commit is convenient to use.

As I understand Docker every container image has two parts this is a group of read-only layers making up the bulk of the image and then a small layer which is writeable where any changes are committed.

When you run commit docker goes ahead and creates a new image this is the base image plus changes you made (the image created is a distinct image), it copies up the code to the thin writable layer. So a new read-only layer is not created it merely stores the deltas you make into the thin writeable layer.

Don't just take my word for it, take Redhats advice

For clarity that article in step 5 says:

5) Don’t create images from running containers – In other terms, don’t use “docker commit” to create an image. This method to create an image is not reproducible and should be completely avoided. Always use a Dockerfile or any other S2I (source-to-image) approach that is totally reproducible, and you can track changes to the Dockerfile if you store it in a source control repository (git).

Hierarchize answered 9/8, 2018 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.