Docker - 什么是重建并将更新的映像推送到docker cloud的正确方法?

时间:2016-04-19 09:34:49

标签: docker dockerfile docker-image docker-cloud

我目前正在做的事情:

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

构建命令:

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

标记:

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

推:

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

执行这些步骤后,存储库映像仍未更新。我一直收到这条消息 - "图层已经存在"。

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

我做错了什么?

3 个答案:

答案 0 :(得分:14)

我发现了这个问题,感谢@ lorenzvth7!

我有两张带有相同标签的图片(我正推向云端)。

解决方案是:

  1. 检查您的图片并找到两个或多个具有相同标签的图片:

    docker images 
    
  2. 删除它们:

    docker rmi --force 'image id'
    
  3. 多数民众赞成!按照我上面的问题中的步骤进行操作。

答案 1 :(得分:4)

另一种解决方案,尽管蛮力,是在再次推送之前使用-no-cache 标志重建。

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

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

docker push my-djnago-app:latest

答案 2 :(得分:0)

我也遇到了这个问题(In my web application),就像这样:

# 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

我尝试了我的解决方案,它奏效了!

# 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>

终端输出:

# 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

然后,打开my web appliction,它更新了最新版本!