Docker Community Forums

Share and learn in the Docker community.

Define layers in Dockerfile

build
docker

(Svstephen) #1

Currently the docker build creates a new layer for each command in the docker file. It would be useful to optionally define sections of a Dockerfile to be run inside the same layer by adding LAYERSTART and LAYEREND commands. This could be used to remove unnecessary layers. For example:

Generates 3 layers

...
COPY file1 /some/location
COPY file2 /some/other/location
RUN chmod +x /some/location/file1
...

Generates 1 layer

...
LAYERSTART
COPY file1 /some/location
COPY file2 /some/other/location
RUN chmod +x /some/location/file1
LAYEREND
...

all commands outside LAYERSTART and LAYEREND create new layers like normal