What is a Dockerfile?
Why Interviewers Ask This
This is a classic screening question for Docker roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
A Dockerfile is a plain text file (named exactly "Dockerfile", no extension) containing a series of instructions that Docker executes to build an image. Each instruction creates a new layer in the image. Key instructions: FROM — specifies the base image: FROM node:20-alpine; RUN — executes a command during build: RUN npm install; COPY — copies files from host into the image: COPY . /app; ADD — like COPY but also supports URLs and auto-extracts archives (prefer COPY for clarity); WORKDIR — sets the working directory for subsequent instructions: WORKDIR /app; EXPOSE — documents which port the container listens on (informational, doesn't actually publish): EXPOSE 3000; ENV — sets environment variables: ENV NODE_ENV=production; ARG — build-time variable (not persisted in image); CMD — default command to run when container starts (overridable): CMD ["node", "app.js"]; ENTRYPOINT — sets the main process (CMD arguments are appended): ENTRYPOINT ["node"]; VOLUME — declares a mount point; USER — sets the user to run subsequent commands; LABEL — adds metadata.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last Docker project, I used this when...' immediately makes your answer more credible and memorable.