Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker updating image along when dockerfile changes

Tags:

docker

I'm playing with docker by creating a Dockerfile with some nodejs instructions. Right now, every time I make changes to the dockerfile I recreate the image by running sudo docker build -t nodejstest . in my project folder however, this creates a new image each time and swallows my ssd pretty soon.

Is there a way I can update an existing image when I change the dockerfile or I'm forced to create a new one each time I make changes to the file?

Sorry if it's a dumb question

like image 547
Romeo Mihalcea Avatar asked Sep 14 '13 16:09

Romeo Mihalcea


People also ask

How do I automatically update Docker images?

By pushing a new Docker image to your repository, Watchtower will automatically trigger a chain of events to update your running container's base Docker image. When Watchtower detects a new push, it will pull the new base image, gracefully shutdown your running container, and start it back up.

Can Docker images be updated?

To update to a newer image, you first need to pull the new version. Run the docker pull command followed by a colon and the name and the tag of the newer image: the name and tag that you took note of previously.

How do I save a Docker image after making changes?

If you want to make changes inside the container and want those changes to persist, you can use the Docker commit command. This will create a new image with all the changes made to the previous container committed to it.

Should I apt get update in Dockerfile?

Removed the apt-get upgrade line, as it is not encouraged in a Dockerfile, as suggested by Docker itself. Here is the relevant part: Avoid RUN apt-get upgrade and dist-upgrade, as many of the “essential” packages from the parent images cannot upgrade inside an unprivileged container.


2 Answers

Docker build support caching as long as there is no ADD instruction. If you are actively developing and changing files, only what is after the ADD will be rebuilt.

Since 0.6.2 (scheduled today), you can do docker build --rm . and it will remove the temporary containers. It will keep the images though.

In order to remove the orphan images, you can check them out with docker images, and perform a docker rmi <id> on one of them. As of now, there is an auto-prune and all untagged images (orphans, previous builds) will be removed.

like image 97
creack Avatar answered Nov 09 '22 19:11

creack


According to this best practices guide if you keep the first lines of your dockerfile the same it'll also cache them and reuse the same images for future builds

like image 44
Reza S Avatar answered Nov 09 '22 19:11

Reza S