Basic Interview Questions

What is Docker and why is it used?

Docker packages an application and its dependencies into a portable image that runs as an isolated container anywhere Docker runs. It removes "works on my machine" problems, speeds up setup, and is the standard unit of deployment for cloud platforms.

Image vs container?

An image is a read-only template (layers built from a Dockerfile). A container is a running or stopped instance of an image with its own writable layer, network and process. Many containers can run from one image.

Container vs virtual machine?

ContainerVirtual machine
shares the host kernelruns its own guest OS
MBs, starts in secondsGBs, starts in minutes
process-level isolationhardware-level isolation
high densityfewer per host

What is a Dockerfile?

A text file with instructions (FROM, COPY, RUN, CMD...) that docker build executes to create an image. Each instruction produces a cached layer.

What does docker run -d -p 8080:80 nginx do?

Pulls the nginx image if needed, creates a container, runs it in the background (-d) and maps host port 8080 to container port 80 (-p), so the site is available at http://localhost:8080.

How do you see logs and get a shell in a container?

docker logs -f <container>
docker exec -it <container> sh