![docker run image at revision docker run image at revision](https://i.imgur.com/zSpAe.jpg)
RUN apk del python3 & apk add -no-cache perl If following the previous method I'd have had to create a new Dockerfile like so - FROM dummy:0.1 Consider again the previous Dockerfile, what if I did not have to keep Python3 in that image, and replace the Python3 package and the command with the Perl ones? Because it adds additional layers and increases the image size by quite a lot.Ī better method would be to not use the image as a base image, but change that image's actual Dockerfile. Some tasks may require us to alter an existing layer, although you can do that using the previous method with a bunch of contradictory RUN instructions (like deleting files, removing/replacing packages added in some previous layer), it isn't an ideal solution or what I'd recommend. With the FROM command in a Dockerfile, you take some image as a base and build on it, or add layers to it. Since the existing layers of an image are read-only, you cannot directly modify them through a new Dockerfile. For that, you need to follow the next method. 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.
![docker run image at revision docker run image at revision](https://ledseq.com/wp-content/uploads/2014/03/closeUp.jpg)
These are the reasons one might want to modify an existing docker image. The downside of this r/w layer is that changes made in this layer is not persistent, although you can use volumes to persist some data, sometimes you may need/want to add a layer before some existing layer, or delete a layer from an image or simply replace a layer. But for the containers' processes to be able to perform r/w, another layer is added on top of the existing RO layers when creating the containers, this is writable and not shared by other containers. This is beneficial because since these layers are read-only, no process associated with a running instance of this image is going to be able to modify the contents of this image, therefore, these layers can be shared by many containers without having to keep a copy for each instance. 35 hours ago /bin/sh -c #(nop) ADD file:80bf8bd014071345b… 5.61MBĮach of these layers is read-only.
![docker run image at revision docker run image at revision](https://static.us-east-1.prod.workshops.aws/public/311c5cbc-f9b8-44f9-83ea-bcc34feed14b/static/images/02-run-task.png)
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.
![docker run image at revision docker run image at revision](https://aws1.discourse-cdn.com/business4/uploads/gitlab/original/3X/7/b/7bb588a5531864da385af9448d051a9333f82cc2.png)
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.