Top 10 Common DevOps/SRE Interview Questions and Answers on Dockerfiles
Last updated
Last updated
RUN
and CMD
?RUN
: Executes commands during the image build process, creating a new layer. Typically used for installing software packages.
Example:
CMD
: Specifies the default command to run when the container starts. It executes at runtime, not during the build process.
Example:
Multi-stage builds allow you to use multiple FROM
statements in your Dockerfile to create temporary stages that help keep the final image smaller.
Example:
EXPOSE
Instruction?EXPOSE
: Documents the ports on which the container listens at runtime. It does not publish the ports but serves as a hint for users running the container.
To make the ports accessible, use the -p
flag with docker run
.
Example:
ARG
and ENV
?ARG
: Defines a variable that users can pass at build time using docker build --build-arg
. It is not available at runtime.
Example:
ENV
: Sets environment variables that are available both during build time and at runtime.
Example:
Use multi-stage builds to separate build dependencies from runtime dependencies.
Example:
Combine commands in RUN
statements to reduce the number of layers.
Example:
Use smaller base images, like Alpine, to minimize the image size.
Use Docker volumes or bind mounts to persist data outside of the container’s filesystem. This ensures data remains available even when the container is restarted or recreated.
Example:
LABEL
Instruction?LABEL
: Adds metadata to the image, such as maintainer information, version, or description. This helps with the documentation and management of images.
Example:
HEALTHCHECK
in a Dockerfile?HEALTHCHECK
: Defines a command to test whether the container is functioning correctly. If the health check fails, Docker can automatically restart the container or take other corrective actions.
Example:
Avoid hardcoding secrets in Dockerfiles. Instead, use Docker secrets, environment variables, or external tools like HashiCorp Vault to manage sensitive information securely.
Example:
CMD
and ENTRYPOINT
?CMD
: Provides defaults for an executing container. It can be overridden by passing arguments to docker run
.
Example:
ENTRYPOINT
: Configures a container to run as an executable. Commands and arguments provided with docker run
are appended to the ENTRYPOINT
instruction.
Example:
Thank you for reading!🙏 If you enjoyed this article and want to stay updated with more content like this, follow me on my social media channels:
Feel free to connect, and let’s continue the conversation!😊
This course simplifies everything with: ✅ Real-world examples to connect theory with practice. 🛠️ Hands-on labs to build confidence through action. 📚 Clear explanations that make even complex topics easy to understand.
and take the first step toward becoming a Kubernetes pro! 🌟
YouTube:
LinkedIn:
Instagram:
👉 You won’t find a better way to master Kubernetes!