Containerization has transformed software development, and at the heart of it all is Docker. This powerful tool enables seamless application deployment, ensuring consistency across environments.
As organizations prioritize scalability and reliability, Docker expertise has become a must-have skill for DevOps engineers and software developers. Preparing for a Docker interview means mastering container fundamentals, orchestration techniques, and troubleshooting strategies.
This page compiles essential Docker interview questions to help candidates navigate both technical and conceptual aspects of the tool. Whether you’re a beginner or an experienced professional, these questions will refine your understanding, enhance your problem-solving abilities, and equip you to ace your next interview.
- CMD offers executable defaults for an executing container. If the executable needs to be omitted, incorporate ENTRYPOINT instruction with the JSON array format.
- ENTRYPOINT denotes that the instruction within will always run when the container starts. This command gives an option to configure the executables & the parameters. If the DockerFile doesn’t have this command, it would still get inherited from the base image mentioned in the FROM instruction.
- Off: container won’t be restarted if it fails or stops:
- On-failure: The container restarts only when a failure is not occurred by the user.
- Unless-stopped: The container restarts only when a user executes a command to stop it,
- Always: The container is always restarted despite an error or other issues.
- Load balancing,
- Deploying & provisioning of containers,
- Allocation of resources between the containers,
- Monitoring the health of hosts & containers,
- Scaling the containers,
- Switching containers from one host to other when the host is lacking resources or is unavailable.
- docker-version: To understand the installed docker version. Syntax, docker–version
- docker ps: It lists all the docker containers are running with container details. Syntax: docker ps
- docker ps -a: It lists all the containers, including those running, exited, stopped with the details. Syntax: docker ps -a
- docker exec: It accesses the container & runs commands inside that container. Syntax: docker exec (options)
- docker build: It builds an image from the Dockerfile. Syntax: docker build [options] path|URL
- docker rm: It removes the container with a mentioned container id. Syntax: docker rm
- docker rmi: It removes the docker image with a mentioned image id. Syntax: docker rmi
- docker info: It gets detailed information about the Docker installed on the system like the no. of images, containers, paused, running, server version, stopped, volume, runtime, total memory, kernel version, etc. Syntax: docker info
- docker cp: The copies a file from the docker container to the local system. Syntax: docker cp
- docker history: It displays the history of a docker image with a mentioned image name. Syntax: docker history
- Volume Mount-It is stored in a part of the host filesystem & managed by Docker (/var/lib/docker/volumes/ on Linux). Non-Docker processes must not modify this part of the filesystem. Volumes are the best way to persist.
- Bind Mount– It may be stored anywhere in the host system & can even be important system directories or files. Non-Docker processes on a Docker container or Docker host can modify them at any time.
- tmpfs Mount- It is only stored in the host system’s memory & is never written to the host system’s filesystem.
- Define an application environment in the Dockerfile so it can be replicated anywhere
- Define the services of your application in the docker-compose.yml file.
- Run docker-compose up to start & create the entire application.
- Process in a Virtual Machine can’t see processes in other Virtual Machines. On the other hand, Process in a Docker Container can’t see the processes in other Docker Containers.
- Each Virtual Machine has its own root filesystem while Each Docker Container has its own root file system (not Kernal)
- Each Virtual Machine gets its own virtual network adapter. In contrast, Docker can get a virtual network adapter. It has separate ports & IP.
- A virtual machine is a running instance of the physical files Whereas Docker Containers are running instances of a Docker Image.
- Host OS can be different from the guest OS. On the other hand, Host OS can be different from the Container OS.
- A Dockerfile can be defined as a text document that contains all the instructions or commands for users to assemble the image.
- Docker Compose refers to a tool for running & defining multi-container Docker apps. You can use a YAML file to configure your app’s services through the Docker Container. Thereby, with a single command, you can start & create all services from your configuration. By default, docker-compose expects the Compose file’s name as docker-compose.yml. If the compose file has different names, you can specify it with the -f flag.
- Use a JSON configuration file (it a preferred option, as it keeps all configurations in one place).
- Use flags when starting the dockerd.
- Up Command: It keeps a Docker Compose up; one can restart or start all the drivers, networks, & services associated with the application specified in the docker-compose.yml file. If the docker-compose is run in the “detached” mode, it exits & shows no logs once the containers are started.
- Run Command– Through this command, the docker-compose can run ad-hoc tasks based on the business needs. Here, the service name needs to be provided & the docker only starts that specific service and other services to which the target service is dependent. It helps to test the containers & perform tasks such as adding or removing data to the container volumes.
- Start Command– This command helps to restart those containers which were already created & stopped. It does not help to create new containers on its own.