Create a docker image that retains the base layer and my changes to it in separate layers

43 views Asked by At

I'm trying to create a base docker image that's used by many applications. I use ansible to configure the image so I have all that configuration in 1 place. The ansible playbook is doing things like installing nginx-extras, nodejs and some utils.

FROM ubuntu:jammy as base

COPY . ./playbook
RUN apt install ansible
RUN ansible-playbook ...
RUN apt remove ansible
RUN rm -rf ./playbook

FROM scratch
COPY --from=base / /

This creates a 1 layer image that has no references to files deleted in the first step. I don't want to leave my ansible playbook embedded in the image and I want to free up the space from removed packages/files.

How can I create an image with 2 layers:

  1. ubuntu:jammy
  2. My changes to ubuntu:jammy

The idea being that this would make my image smaller because ubuntu:jammy is cached. It also makes it clearer that this image is derived from ubuntu:jammy.

0

There are 0 answers