66

What I'm currently doing:

Dockerfile:

FROM python:3.5.1

ENV PYTHONUNBUFFERED 1

RUN mkdir /www
WORKDIR /www
ADD deps.txt /www/
RUN pip3 install -r deps.txt
ADD . /www/
RUN chmod 0755 /www/docker-init.sh

Build command:

docker build -t my-djnago-app:latest .

Tagging:

docker tag my-djnago-app:latest lolorama/my-djnago-app-img:latest

Pushing:

docker push lolorama/my-djnago-app-img:latest

After following these steps, the repository image still hasn't updated. I keep getting this message - "Layer already exists".

The push refers to a repository [docker.io/lolorama/my-django-app-img]
fd5aa641b308: Layer already exists
d9c60c6f98e8: Layer already exists
d9d14867f6d7: Layer already exists
64ce166099ca: Layer already exists
73b670e35c69: Layer already exists
5f70bf18a086: Layer already exists
9ea142d097a5: Layer already exists
52f5845b1de0: Layer already exists
e7fadb3ab9d4: Layer already exists
cef72744de05: Layer already exists
591569fa6c34: Layer already exists
998608e2fcd4: Layer already exists
c12ecfd4861d: Layer already exists

What am I doing wrong?

Ibrahim Tareq
  • 336
  • 2
  • 12
Alex T
  • 4,331
  • 3
  • 29
  • 47
  • did you change something in your dockerfile? Otherwise the docker build will rebuild the same image (this will go very fast because everything exists). When you push the same image the repo will detect that all the necessary layers already exist and will change anything. – lvthillo Apr 19 '16 at 10:56
  • @lorenzvth7 Dockerfile didn't change. I've change apps code that imports with `ADD . /www/` – Alex T Apr 19 '16 at 14:23
  • Did you rebuild your image after changing changing the code in the www/ folder? Because that's necessary. after that you have to tag the new image and push. – lvthillo Apr 19 '16 at 15:52
  • @lorenzvth7 Yes, I do.. – Alex T Apr 19 '16 at 18:41
  • Hmm weird, how old is the image 'my-djnago-app:latest' after performing the docker build (with the new source code)? – lvthillo Apr 19 '16 at 19:15
  • @lorenzvth7 docker images returns 10 seconds ago. I assume that image build works properly and real problem is in the tagging or pushing phase. – Alex T Apr 19 '16 at 20:02
  • Tried just the same but I have my new layer in the push to the registry. [ 32a5845afb6f: Pushed 2b89e3f15cc0: Layer already exists. ... ]Maybe try to delete the image (locally and on the registry) and try it all over again. – lvthillo Apr 19 '16 at 20:43
  • @lorenzvth7 thank for the tip, I found the problem. I've had two images with same tag (which i was pushing to cloud) – Alex T Apr 20 '16 at 07:54
  • why not tag it as `lolorama/my-djnago-app-img:latest` in the build command instead of building it and then changing the tag? – DataMan Apr 11 '19 at 17:39

5 Answers5

44

I found the problem, thanks to @lorenzvth7!

I've had two images with same tag (which i was pushing to cloud).

Solution is:

  1. Inspect your images and find two or more with the same tag:

    docker images 
    
  2. Delete them:

    docker rmi --force 'image id'
    
  3. Thats it! Follow steps from my question above.
Alex T
  • 4,331
  • 3
  • 29
  • 47
  • 28
    This seems really heavy-handed for something that's done regularly. I feel like we're missing something. – sudo Oct 02 '17 at 19:12
  • When this happens I just re-tag my images and push. Sometimes the tagging doesn't work? Strange. – David S. Oct 16 '18 at 15:33
18

Another solution, albeit bruteforce, is to rebuild with the --no-cache flag before pushing again.

docker rmi --force my-djnago-app:latest

docker build -t my-djnago-app:latest . --no-cache

docker push my-djnago-app:latest
Timothy Perez
  • 20,154
  • 8
  • 51
  • 39
1

I meet the problem as well(In my web application), like this:

# when I push my contaimer to repo
$ docker push <container>
The push refers to repository [docker.io/xx/getting-started]
fd5aa641b308: Layer already exists
d9c60c6f98e8: Layer already exists
d9d14867f6d7: Layer already exists
64ce166099ca: Layer already exists
73b670e35c69: Layer already exists
5f70bf18a086: Layer already exists
9ea142d097a5: Layer already exists
52f5845b1de0: Layer already exists

I try my Solution, and it's works!

# force remove image
$ docker rmi --force <image-id>
# tag for image
$ docker tag <image-name> <your-dockerHub-username>/<image-name>
# push image, just done!
$ docker push <your-user-name>/<image-name>

terminal output:

# when I push my container to repo
$ docker push <container>
The push refers to repository [docker.io/xx/getting-started]
# it'll push your part of changes
fd5aa641b308: Pushed
d9c60c6f98e8: Pushed
d9d14867f6d7: Layer already exists
64ce166099ca: Layer already exists
73b670e35c69: Layer already exists
5f70bf18a086: Layer already exists
9ea142d097a5: Layer already exists
52f5845b1de0: Layer already exists

Then, open my web appliction, it's updates the lastest version!

lidean
  • 21
  • 4
  • 3
    hi lidean. its better to copy the logs in **Text** mode. which helps indexing and searching, and users whit same problem can reach here sooner. tanks – Abilogos Jan 29 '21 at 09:22
1

when you build the docker file, add you docker repository name as well.

docker build -t <your-dockerHub-username>/my-djnago-app:latest .

in your scenario,

docker build -t lolorama/my-djnago-app:latest .
Prabah
  • 807
  • 6
  • 12
0

For CI/CD pipelines, I'd recommend --no-cache option as changes to config only will not trigger publish step. There's not much difference between that and rmi prior to build. I've always run into hard-to-find errors that are the result of build caching, and I prefer to do a clean build in CI/CD.