Sobes.tech
Middle+

What do you consider a well-written Docker configuration, and what is not? What are anti-patterns?

sobes.tech AI

Answer from AI

A well-written Docker configuration should be:

  • Simple and understandable — minimal layers, readable Dockerfile.
  • Size-optimized — use lightweight base images, remove temporary files.
  • Idempotent — repeated builds produce the same result.
  • Secure — do not store secrets in the image, use environment variables.
  • Cacheable — layers that change infrequently should be higher up to speed up builds.

Anti-patterns:

  • Using latest without fixing the image version.
  • Multiple RUN commands that can be combined into one.
  • Storing secrets and confidential data in the Dockerfile.
  • Copying unnecessary files into the image.
  • Lack of .dockerignore, leading to a large build context.

Example of a bad Dockerfile:

FROM ubuntu
RUN apt-get update
RUN apt-get install -y curl
COPY . /app
RUN rm -rf /app/tmp

It's better to combine RUN commands and add .dockerignore to exclude unnecessary files.