Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How upgrade a docker image without creating new image?

It seems like the simplest question I can't find the answer for.

  1. I build a docker image.
  2. run docker images shows that it's present.
  3. I then add a new line to the Docker file.
  4. Then I rebuild the image.
  5. The old image is still in docker images and there's now a new image.

How does one simply update the old image without creating a new one?

My docker command: docker build -t nick_app . --force-rm --no-cache

(Note: I just tossed those --force-rm command and --no-cache command' because it seemed like it would work.)

Before:

Dockerfile:

FROM ruby:2.3.3
RUN apt-get update -qq && apt-get install -y
CMD ["echo", "Sup"]

docker images command:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nick_app            latest              421662154c3f        9 minutes ago       746.9 MB
ruby                2.3.3               d00ebde6a601        2 days ago               730.1 MB
hello-world         latest              c54a2cc56cbb        4 months ago          1.848 kB

After: Dockerfile:

FROM ruby:2.3.3
RUN apt-get update -qq && apt-get install -y \
   build-essential
CMD ["echo", "Sup"]

docker images command:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nick_app            latest              bcf9b3667202        3 seconds  ago       746.9 MB
<none>              <none>              421662154c3f        10 minutes ago      746.9 MB
ruby                2.3.3               d00ebde6a601        2 days ago          730.1 MB
hello-world         latest              c54a2cc56cbb        4 months ago        1.848 kB

Every dockerfile change I make creates a new none image on rebuild. They're cumulative so every time I make a change and rebuild I get another none image.

How does one get rid of that intermediate none every time I make a dockerfile change?

like image 721
Dr. Chocolate Avatar asked Nov 24 '16 16:11

Dr. Chocolate


People also ask

Do I have to rebuild Docker image every time?

You don't need to rebuild your Docker image in development for each tiny code change. If you mount your code into your dev container, you don't have to build a new image on every code change and iterate faster. It's a great feeling when you make changes and see the results right away!

How do I create a docker image from an existing image?

You can create a new image by using docker command $docker build -f docker_filename . , It will first read the Dockerfile where the instructions are written and automatically build the image. The instruction in the Dockerfile contains the necessary commands to assemble an image.


1 Answers

Those <none>:<none> are actually the old version of your application, that has lost its named pointer, since you moved the nick_app:latest to your new build.

When building your image, I don't think that you can tell it to destroy the old image, it will simply create a new one. But there is a command that helps you to list or remove those dangling images :

docker images --filter dangling=true #lists all images that are dangling and has no pointer to it
docker rmi `docker images --filter dangling=true -q` #Removes all those images.
like image 124
MagicMicky Avatar answered Sep 29 '22 10:09

MagicMicky