Define layers in Dockerfile

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

1 Like

This is exactly what I thought. Why all the trouble with the multi stage build and stuff… Just add a layer start and end.
This would really help but since this post is already quite old there seem to be nobody interested in such a feature