Sobes.tech
Junior — Middle

Does each command in a Dockerfile create a separate layer of the image?

sobes.tech AI

Answer from AI

Yes, each command (instruction) in a Dockerfile creates a separate layer of the image. This allows for efficient caching during image build: if a layer hasn't changed, Docker reuses it from the cache. However, this also means that too many layers can increase the size of the image and the build time. Therefore, it is often recommended to combine commands, for example, using && in RUN, to reduce the number of layers.