Member-only story

Top 10 Common DevOps/SRE Interview Questions and Answers on Dockerfiles

techwithpatil
3 min readSep 6, 2024

1. What is the Difference Between RUN and CMD?

  • RUN: Executes commands during the image build process, creating a new layer. Typically used for installing software packages.

Example:

RUN apt-get update && apt-get install -y curl
  • CMD: Specifies the default command to run when the container starts. It executes at runtime, not during the build process.

Example:

CMD ["node", "app.js"]

Free Article Link https://blog.techwithpatil.com/blogs/medium-articles/devops-sre-interview-questions-and-answers/top-10-common-devops-sre-interview-questions-and-answers-on-dockerfiles

2. How to Use Multi-Stage Builds in Dockerfiles?

  • 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:

# Build stage
FROM golang:1.17 AS builder
WORKDIR /app
COPY . .
RUN go build -o myapp

# Production stage
FROM alpine:latest
COPY --from=builder /app/myapp /myapp
CMD ["/myapp"]

3. What is the Purpose of the EXPOSE Instruction?

  • EXPOSE: Documents the ports on which the container listens at runtime. It does not publish the ports but…

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

techwithpatil
techwithpatil

Written by techwithpatil

DevOps & Site Realiability Interview | Cloud | AI Agent | Software Automation https://beacons.ai/techwithpatil

No responses yet

What are your thoughts?