

This method is not going to be much helpful if your intention is to change or delete some existing layer.

Here I'm building on top of dummy:0.1, adding more layers to it as I see fit. Now if I were to think that I now need to use Perl instead of Python3 to print "Hello World", but I also don't want to remove Python3, I could just use the dummy:0.1 image as the base image (since Python3 is already there) and build from that like the following FROM dummy:0.1 Say the image build from that image is named dummy:0.1. Unless an image is built from scratch, every image is a modification to the same parent base image.Ĭonsider the previous Dockerfile. This is when you take the image you want to modify, and add layers to it to build a new child image. Let me explain which method should be used when, and how. Modifying the actual Dockerfile of the image you want to change.Using the image that you want to modify as a base image and build a child image.There are two ways you can use a Dockerfile to modify an image. So if you were to add a layer to the image, you can simply add another Dockerfile instruction to it, to remove one you would remove a line and to change a layer, you would change the line accordingly. Now since each Dockerfile command represents one layer of the image, modifying each line of a Dockerfile will change the respective image as well. Modifying a docker image essentially means modifying the layers of an image.

Method 1: Modifying docker image through the Dockerfile I'll explain both methods, and at the end, I'll also add which use case would be better for the method in context.
DOCKER RUN IMAGE AND ATTACH APK
articles/Modify a Docker Image on modify-docker-images took 12sī997f897c2db 10 seconds ago /bin/sh -c #(nop) ENTRYPOINT ["python3" "-c… 0BĮe217b9fe4f7 10 seconds ago /bin/sh -c apk add -no-cache python3 43.6MBĢ8f6e2705743 35 hours ago /bin/sh -c #(nop) CMD 0B Īnd then using the command docker image history on the built image. You can confirm that by building the image: docker image built -t dummy:0.1. Since there are a total of three Dockerfile commands, the image built from this Dockerfile, will contain a total of three layers. For example, consider the following Dockerfile: FROM alpine:latestĮNTRYPOINT What exactly is modifying a docker image?Ī container image is built in layers (or it is a collection of layers), each Dockerfile instruction creates a layer of the image. In previous articles we have discussed updating docker container and writing docker files. I presume you are a tad bit familiar with Docker and know basics like running docker containers etc.
