0% found this document useful (0 votes)
3 views2 pages

Docker Interview Qa

This document serves as a quick reference for Docker interview questions, covering core concepts, Dockerfile instructions, common commands, and conceptual scenarios. It explains the differences between images and containers, the purpose of Dockerfiles, and key commands for managing containers and images. Additionally, it addresses the advantages of using Docker and its relationship with Kubernetes, along with practical troubleshooting tips.

Uploaded by

eduatguna
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Docker Interview Qa

This document serves as a quick reference for Docker interview questions, covering core concepts, Dockerfile instructions, common commands, and conceptual scenarios. It explains the differences between images and containers, the purpose of Dockerfiles, and key commands for managing containers and images. Additionally, it addresses the advantages of using Docker and its relationship with Kubernetes, along with practical troubleshooting tips.

Uploaded by

eduatguna
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Docker Interview Quick Reference

Core concepts, commands, and ready-to-say answers

Core Concepts
Q: What is Docker?
A platform that packages an application with everything it needs (code, dependencies, runtime) into
a single unit called an image, so it runs consistently anywhere.

Q: What is the difference between an image and a container?


An image is a packaged, read-only blueprint of an application. A container is a running instance of
that image – lightweight and isolated.

Q: What is a Dockerfile?
A text file containing step-by-step instructions Docker follows to build an image – e.g. which base
OS/runtime to start from, what files to copy in, what dependencies to install, and what command to
run on startup.

Q: Explain the difference between docker build and docker run.


docker build reads a Dockerfile and produces an image. docker run starts a container from an
existing image.

Q: What does -p 5000:5000 mean in docker run?


It maps a port on the host machine (left side) to a port inside the container (right side), so traffic
sent to the host port is forwarded into the container.

Q: Why do we set host to [Link] instead of [Link] in a containerized app?


[Link] only accepts connections from inside the container itself. [Link] listens on all interfaces,
allowing Docker’s port mapping to reach the app from outside the container.

Dockerfile Instructions
Q: What do FROM, WORKDIR, COPY, RUN, and CMD each do?
FROM – sets the base image to build on top of.
WORKDIR – sets the working directory inside the image.
COPY – copies files from your machine into the image.
RUN – executes a command at build time (e.g. installing dependencies).
CMD – specifies the command that runs when a container starts (not at build time).

Q: What’s the difference between RUN and CMD?


RUN executes during the image build and its result is baked into the image (e.g. installing packages).
CMD only defines what happens when a container is started from the image – it does not run during
build.

Common Commands
Q: How do you list running containers? All containers?
docker ps shows running containers. docker ps -a shows all containers, including stopped ones.
Q: How do you view a container’s output/logs?
docker logs <container> – shows everything the app has printed since it started; the first tool to
check when something isn’t working.

Q: How do you get a shell inside a running container?


docker exec -it <container> bash – opens an interactive shell inside the running container for
direct inspection or debugging.

Q: How do you stop and remove a container?


docker stop <container> stops it; docker rm <container> removes the stopped container object.
docker rm -f <container> does both in one step.

Q: How do you list and remove images?


docker images lists images; docker rmi <image> removes one.

Conceptual / Scenario Questions


Q: Why use Docker instead of just installing dependencies directly on a server?
Consistency and isolation – the app behaves the same on any machine because the environment travels
with it. It also avoids ”works on my machine” issues and lets multiple apps run on one host without
dependency conflicts.

Q: How does Docker relate to Kubernetes?


Docker builds and runs individual containers. Kubernetes orchestrates many containers across multi-
ple machines – handling scheduling, scaling, self-healing, and networking between them. Kubernetes
runs the containers that Docker (or a similar tool) builds.

Q: If a container keeps exiting immediately after docker run, what would you check?
docker logs <container> first, to see the application error. Also check docker ps -a to confirm
its exit status, and review the Dockerfile’s CMD to make sure the start command is correct.

Q: What happens to data inside a container if it’s removed?


It’s lost, since containers are ephemeral by default. Persistent data needs to be stored using Docker
volumes, which exist outside the container’s lifecycle.

Your Honest Talking Point


Q: Have you worked with Docker hands-on?
”Yes – I’ve built and run containerized applications, including writing my own Dockerfile for a small
Flask app: setting the base image, installing dependencies, and running it as a container with port
mapping. I’m continuing to build hands-on depth alongside learning Kubernetes, since Kubernetes
orchestrates the containers Docker builds.”

You might also like