HomebaseWorks

Docker interview questions

Docker questions common in DevOps and backend interviews, with answers that explain how things work.

EWritten by the HomebaseWorks editorial team · reviewed 26 Oct 2026
1
What is the difference between an image and a container?

An image is a read-only template made of layers, built from a Dockerfile or pulled from a registry. A container is a running instance of an image with its own writable layer. I can start many containers from one image, and removing a container does not change the image.

2
How is a container different from a virtual machine?

Containers share the host operating system's kernel and isolate processes, so they are light and start in seconds. A virtual machine runs a full guest operating system on virtual hardware, which uses more resources but gives stronger isolation. I would use containers to package applications and VMs when I need a different kernel or stricter separation.

3
What is the difference between CMD and ENTRYPOINT?

ENTRYPOINT sets the program that always runs, and CMD sets default arguments or a default command that docker run arguments can replace. For example, with ENTRYPOINT python app.py and CMD --port 8000, running the image with --port 9000 changes only the port. I use the exec form for both so signals reach the app.

Advertisement
4
How do you make Docker builds faster?

I order the Dockerfile so things that change rarely come first, for example copying the dependency file and installing packages before copying the source code. That way code changes reuse the cached install layer. I also add a .dockerignore file and use a smaller base image where it fits.

5
How do you keep a database's data when its container is replaced?

I mount a named volume at the database's data directory, for example pgdata at /var/lib/postgresql/data. The volume lives outside the container's writable layer, so removing and recreating the container keeps the data. I still take regular backups, because a volume is not a backup.

6
Two services in Docker Compose cannot connect. How do you troubleshoot?

First I check that the app uses the other service's name as the host, not localhost, and the container port rather than the published host port. Then I check docker compose ps and logs to see if the target service is actually running and ready. Finally I use docker compose exec to open a shell in one container and test the connection directly.

Practise out loud. Say each answer once as written, then again in your own words with your own number or story.

Have a number ready. "My Docker score is at benchmark on a timed test" is a stronger answer than "I am good at it". Take the test and quote the result.

Advertisement
Continue with Docker4 lessons · 1 interview set · 1 test · 1 certificate
Not tested

More in Cloud and DevOps