Create common layers for two different docker images

  docker, dockerfile, image

When I create docker image on my local and use docker inspect, I got following layers

"Layers": [
   "sha256:721384ec99e56bc06202a738722bcb4b8254b9bbd71c43ab7ad0d9e773ced7ac",
   "sha256:5e6abd2adb12979c5c361f46711677590540cb8955974ad318ba2fdff6491811",
   "sha256:9b9411b58604d49fd1283430d3bbdbc238b3d25b16c729aac49e9158eba8da69",
   "sha256:fa51dce368709d6994484c6f87fd465eae2dbe6ae7876f6fe4adc17283ad72ed",
   "sha256:2975210efdc28244070b0fede0d3f233a21b096907e54235cd34a6ca4f86e4bc"
]

what I need to do if I want same layers except only one layer for different image?
meaning, I want below layers only with combination of different layers in another image.

"sha256:5e6abd2adb12979c5c361f46711677590540cb8955974ad318ba2fdff6491811",
"sha256:9b9411b58604d49fd1283430d3bbdbc238b3d25b16c729aac49e9158eba8da69",
"sha256:fa51dce368709d6994484c6f87fd465eae2dbe6ae7876f6fe4adc17283ad72ed",
"sha256:2975210efdc28244070b0fede0d3f233a21b096907e54235cd34a6ca4f86e4bc"

I tried using same layers in dockerfile but that did not work. These are the layers I used

Dockerfile :

FROM alpine:3.6
RUN apk update
RUN echo  "test message"
RUN apk add curl
RUN apk add wget
RUN apk add vim

I want two different images with common layers except the first layer. please help.

Source: Docker Questions

LEAVE A COMMENT