2

Build a docker image using Dockerfile pushing same image to Artifactory. I noticed that when using apk --no-cache the sha256 changes although Dockerfile did not.

I pushed 3 different images to Artifactory, and when checking i noticed 3 different layers - does it means it occupies 3 layers instead of having reference to the first layer pushed?

I build the same Dockerfile 3 times, and pushed the image to Artifactory. Checking the image layers i noticed 3 images with different layers (different sha256).

FROM alpine:3.9

ADD resources/repositories /etc/apk/repositories
RUN apk --no-cache add curl && apk --no-cache add --repository  http://myartifactory.com:8081/artifactory/alpine-nl-remote/alpine/edge/testing gosu

Running (where build 1 changes to 2 and 3)

docker build -t myartifactory.com/apline:3.9-1
docker push

Checking Artifactory I now have 3 layers each image. Once layer is different and two layers are same in all 3 images

Same image should be build with same sha256 and Artifactory should have one copy of the image and 2 more references pointing to that image

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
  • Do the layers that are the same across the images have the same SHA256? If that is the case, Artifactory has indeed stored it once and simply references the layers in other Docker images. – retgits Apr 29 '19 at 17:52

1 Answers1

0

apk --no-cache to install same package may get different sha256, depends on is there any local cache.The reason image changed is because file metadata like mtime or atime changed.

You should build a base layer which installed all dependencies, then build from the base.

wener
  • 7,191
  • 6
  • 54
  • 78