Skip to content
Laviyx Learn

Try

Docker and Kubernetes course menu

Docker Interview Questions for Beginners and Freshers

Beginner Docker interview questions with answers: images and containers, Docker vs virtual machines, Dockerfile basics, common commands, volumes, ports and Docker Compose.

Beginner3 min readUpdated
On this page

These questions come up in most interviews for fresher developer and DevOps roles. Try answering aloud before you read each answer.

Basics#

1. What is Docker?#

Show solution

A platform for packaging an application with its dependencies into a container, so that it runs the same way on any machine with Docker.

2. What is the difference between an image and a container?#

Show solution

An image is a read-only template with the app and its dependencies. A container is a running instance of an image, with its own writable layer. One image can run as many containers.

3. How is a container different from a virtual machine?#

Show solution

A virtual machine includes a full operating system, and runs on a hypervisor. A container shares the host's kernel and isolates only the process. Containers are smaller and start in seconds; virtual machines give stronger isolation.

4. What is a Dockerfile?#

Show solution

A text file of instructions for building an image, such as FROM, COPY, RUN and CMD. You build it with docker build.

5. What is Docker Hub?#

Show solution

The default public registry, where images are stored and shared. docker pull downloads from it, and docker push uploads to it.

Commands#

6. What do docker run, start and exec do?#

Show solution

docker run creates and starts a new container. docker start restarts a stopped one. docker exec runs a command inside a running one.

7. How do you list containers and images?#

Show solution

docker ps lists running containers, docker ps -a includes stopped ones, and docker images lists images.

8. How do you read a container's logs?#

Show solution

docker logs name, with -f to follow and --tail 50 for the last lines.

9. How do you get a shell inside a container?#

Show solution

docker exec -it name sh, or bash if the image has it.

10. What does -p 8080:80 mean?#

Show solution

It publishes a port: traffic to port 8080 on the host goes to port 80 in the container. The host side is on the left.

11. What does -d do?#

Show solution

It runs the container in the background (detached mode).

12. What is the difference between docker stop and docker kill?#

Show solution

stop sends SIGTERM, and after a timeout, SIGKILL, so that the app can shut down cleanly. kill sends SIGKILL at once.

Dockerfile#

13. What is the difference between RUN and CMD?#

Show solution

RUN runs during the build, and its result is saved in the image. CMD sets the default command that runs when a container starts.

14. What is the difference between CMD and ENTRYPOINT?#

Show solution

CMD is a default that arguments to docker run replace. ENTRYPOINT sets a fixed program, and arguments are added to it.

15. What is the difference between COPY and ADD?#

Show solution

COPY copies files. ADD can also unpack local archives and fetch URLs. Prefer COPY, because it is predictable.

Data and networks#

16. What happens to data when a container is removed?#

Show solution

Data in the container's writable layer is lost. To keep it, use a volume or a bind mount.

17. What is the difference between a volume and a bind mount?#

Show solution

Docker manages volumes in its own storage, which suits production data. A bind mount shares a chosen host folder, which suits development.

18. How do containers talk to each other?#

Show solution

On a user-defined network, they reach each other by container or service name. localhost inside a container means that container itself.

Compose#

19. What is Docker Compose?#

Show solution

A tool for defining multi-container apps in a YAML file. docker compose up -d starts everything, and docker compose down removes it.

20. Why should you avoid the latest tag?#

Show solution

It does not mean the newest, and it can change at any time, which makes builds unpredictable. Use specific versions.

Next: Intermediate Questions.

Finished this lesson?

Some links are affiliate links. If you buy through them, Laviyx Learn may earn a commission at no extra cost to you. As an Amazon Associate, we earn from qualifying purchases.