Operations 20 min read

Docker Interview Questions and Essential Knowledge

This article compiles common Docker interview questions and provides detailed explanations, covering Docker fundamentals, use cases, advantages, differences from virtual machines, core components, installation steps, storage configuration, image management, container creation, networking modes, data volumes, private registry setup, backup procedures, and MySQL deployment, all illustrated with practical command examples.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Docker Interview Questions and Essential Knowledge

Introduction

This article summarizes common Docker interview questions and pitfalls in a Q&A format for readers.

1. What is Docker?

Docker is an open‑source application container engine written in Go and released under the Apache 2.0 license.

It runs applications inside Linux containers, providing a lightweight alternative to virtual machines.

Containers enable the creation of portable, self‑contained environments on a single host.

Docker’s logo shows a blue whale pulling many containers, where the whale represents the host and each container represents an isolated application.

2. Docker Use Cases

Automated packaging and publishing of web applications.

Continuous integration, testing, and release pipelines.

Deploying and scaling backend services such as databases.

Building private PaaS platforms (e.g., OpenShift, Cloud Foundry).

In particular, Docker is ideal for internal development environments because it eliminates the overhead of separate virtual machines and allows easy sharing of images across teams.

3. Advantages of Docker

Flexibility – even complex applications can be containerized.

Lightweight – containers share the host kernel.

Replaceability – instant updates and upgrades.

Portability – build locally, deploy to the cloud, run anywhere.

Scalability – easily increase the number of container replicas.

Stackability – services can be vertically or horizontally stacked.

Docker provides an open platform for developing, delivering, and running applications, separating the application from the underlying infrastructure.

4. Difference Between Docker and Virtual Machines

Virtual machines add a hypervisor layer and emulate hardware (CPU, memory, network), each with its own kernel. Docker containers isolate resources (filesystem, processes, devices, network) using namespaces and cgroups, sharing the host kernel, which results in lower resource consumption but slightly weaker isolation.

5. Three Core Components of Docker

Image

An image is a read‑only template (similar to a VM snapshot) that contains everything needed to run an application, including code, runtime, libraries, environment variables, and configuration files.

Container

A container is a runnable instance created from an image; it is isolated from other containers and can be started, stopped, or removed.

Registry

Registries store multiple images and tags. Docker Hub ( https://hub.docker.com ) is the largest public registry; private registries can also be deployed.

6. Quick Installation of Docker

Install dependencies and Docker packages on CentOS:

yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@centos7 ~] yum -y install docker-ce docker-ce-cli containerd.io
# docker ps -- view Docker containers

Enable and start the service:

# systemctl enable docker
# systemctl start docker
# systemctl status docker
# docker ps -- view containers
# docker version
# docker info

7. Changing Docker Storage Location

Default location: /var/lib/docker . Check current location with docker info | grep "Docker Root Dir" .

To move the directory:

systemctl stop docker
mkdir -p /root/data/docker
mv /var/lib/docker /root/data/docker
ln -s /root/data/docker /var/lib/docker

8. Common Image Management Commands

Search Images

docker search <keyword>

Pull Images

docker pull <repository[:tag]> (defaults to latest if no tag is specified).

Inspect Image Details

docker inspect <image-id>

List Image Information

REPOSITORY : image source repository.

TAG : tag identifying a specific version.

IMAGE ID : unique identifier.

CREATED : creation timestamp.

SIZE : image size.

Tag and Remove Images

Tag: docker tag <source> <name:tag>

Remove: docker rmi <repository:tag> or docker rmi <image-id> [-f]

Save and Load Images

# docker save -o myimage.tar myimage
# docker load -i myimage.tar

9. Creating a Docker Container

# docker images   -- list images
docker run -d --name centos7.8 -h centos7.8 \
  -p 220:22 -p 3387:3389 \
  --privileged=true \
  centos:7.8.2003 /usr/sbin/init

# Enter container
docker exec -it centos7.8 bash
cat /etc/redhat-release   # view OS version

10. Standard Docker Run Process

Check if the image exists locally; if not, pull from a registry.

Create and start a container from the image.

Mount a writable layer on top of the read‑only image layer.

Bridge a virtual network interface to the container.

Assign an IP address from the bridge’s address pool.

Execute the user‑specified application; the container stops when the process exits.

11. Docker Network Modes

host

Use --net=host ; the container shares the host’s network namespace and IP address.

container

Use --net=container:NAME_or_ID ; the new container shares the network namespace of an existing container.

none

Use --net=none ; the container gets a network namespace but no network interfaces.

bridge

Default mode; Docker creates a docker0 bridge, assigns each container its own namespace, IP, and connects via a veth pair.

12. Docker Data Volumes

Volumes are special directories inside containers that can be mounted from the host, allowing data persistence independent of the image.

13. Setting Up a Private Docker Registry

# Pull registry image
docker pull registry
# Run registry container
docker run -di --name registry -p 5000:5000 registry
# Enable restart on boot
docker update --restart=always registry
# Verify
docker ps -a --format "table {{.ID}}	{{.Names}}	{{.Status}}"
# Access catalog
http://192.168.1.54:5000/v2/_catalog
# Configure daemon.json for insecure registry
{ "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"], "insecure-registries": ["192.168.1.54:5000"] }
# Restart Docker
systemctl restart docker

14. Docker Backup and Migration

# Commit container to image
docker commit redis myredis
# Save image to tar
docker save -o myredis.tar myredis
# Transfer tar to another host (scp)
scp myredis.tar user@host:/opt
# Load on target host
docker load -i myredis.tar
# Remove old container and image before restore
docker stop myredis
docker rm myredis
docker rmi myredis

15. Deploying MySQL with Docker

# Pull MySQL images
docker pull mysql:5.7.30
docker pull mysql:8.0.20
# Run containers
mkdir -p /usr/local/mysql5730 && \
mkdir -p /usr/local/mysql8020

docker run -d --name mysql5730 -h mysql5730 \
  -p 3309:3306 \
  -v /usr/local/mysql5730/conf:/etc/mysql/conf.d \
  -e MYSQL_ROOT_PASSWORD=root -e TZ=Asia/Shanghai \
  mysql:5.7.30

docker run -d --name mysql8020 -h mysql8020 \
  -p 3310:3306 \
  -v /usr/local/mysql8020/conf:/etc/mysql/conf.d \
  -e MYSQL_ROOT_PASSWORD=root -e TZ=Asia/Shanghai \
  mysql:8.0.20
# Access MySQL inside container
docker exec -it mysql5730 bash
mysql -uroot -proot
# Remote access
mysql -uroot -proot -h192.168.59.220 -P3309

These sections provide a comprehensive guide to Docker concepts, commands, and practical scenarios frequently asked in technical interviews.

DockerDevOpsnetworkLinuxcontainerInterviewImage
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.