Docker Common Interview Questions | Answers

Table of contents

1. What is Docker?

2. What are the three cores of Docker?

3. What is the relationship between warehouse, image and container?

4. The difference between Docker and virtual machine

5. Centralized state of Docker containers

6. How to copy things from the host to the inside of the container?

7. What are the methods of entering the container?

8. How to make the container start automatically when the Docker service starts?

9. How to specify the port mapping of the container?

10. How to view the default port of Container Service

11. How to specify the directory mapping of the container?

12. How to exit a mirrored bash without terminating it?

13. View container log information

14. The Docker configuration file is placed there. How to modify the configuration?

15. What is DockerFile?

16. Commonly used commands for docker


1. What is Docker?

Docker, an open source application container engine, is a tool to implement container technology, allowing developers to package their applications and environments into a mirror, which can be quickly released to any popular operating system.


2. What are the three cores of Docker?

  • Mirroring: Docker's mirroring is a read-only template for creating containers, and one or more containers are started through the mirroring.
  • Container: A Docker container is a running instance created by an image. You can think of a container as a simple version of the Linux environment and the applications running in it.
  • Warehouse: A place to store images, each image has a different tag.

3. What is the relationship between warehouse, image and container?

The warehouse stores images, the host downloads the images through the warehouse, and creates containers through the images.


4. The difference between Docker and virtual machine

  • Kernel: The virtual machine has a separate system kernel, and Docker shares the system kernel with the host machine, so the virtual machine is relatively better isolated from Docker. The virtual machine is equivalent to isolation at the physical level, and Docker is equivalent to isolation at the application level.
  • Size: Docker images are usually tens of megabytes to hundreds of megabytes, which is relatively light, and virtual machines are generally several gigabytes, which are relatively bulky.
  • Speed: The Docker shared host kernel usually starts in seconds, and the virtual machine takes minutes.
  • Resources: Docker takes up less resources, and the virtual machine has a complete system so it takes up more resources.

5. Centralized state of Docker containers

There are 7 states:

  • created
  • restarting
  • running
  • removing (migration)
  • paused
  • exited
  • dead

6. How to copy things from the host to the inside of the container?

Through the docker cp command, you can also copy the internal content of the container to the host.


7. What are the methods of entering the container?

Enter the container through docker exec.


8. How to make the container start automatically when the Docker service starts?

  • When creating a container, add the --restart=always parameter.
  • After the container is created, modify the value of the RestartPolicy parameter in the container configuration file.
  • After the container is created, use the docker update command to update the container's --restart parameter value.

9. How to specify the port mapping of the container?

  • When creating a container, pass -p to specify the port mapping.
  • After the container is created, specify port mappings by modifying the container's configuration file.

10. How to view the default port of Container Service

  • Use docker ps to see what the running port is.
  • You can also check the image information through docker inspect, and then find the port mapping column.

11. How to specify the directory mapping of the container?

  • When creating a container, pass -v to specify a directory map.
  • After the container is created, specify directory mappings by modifying the container's configuration file.

12. How to exit a mirrored bash without terminating it?

  • Press Ctrl+p+q

13. View container log information

use docker logs


14. The Docker configuration file is placed there. How to modify the configuration?

by default:

  • The configuration file of Docker in the Ubuntu system is /etc/default/docker,
  • CentOS system configuration files are stored in /etc/sysconfig/docker

15. What is DockerFile?

A Dockerfile is a text file that contains all the commands needed to build a Docker image. Docker automatically builds images using instructions in a Dockerfile. We can use docker buildcreate automated builds to execute multiple command line instructions in sequence.


16. Commonly used commands for docker

Docker环境信息   info、version
容器生命周期管理  create、exec、kill、pause、restart、rm、run、start、stop、unpause
镜像仓库命令      login、logout、pull、push、search
镜像管理          build、images、import、load、rmi、save、tag、commit
容器运维操作      attach、export、inspect、port、ps、rename、stats、top、wait、cp、diff、update
容器资源管理      volume、network
系统信息日志      events、history、logs
1.events打印容器的实时系统事件
2.history 打印出指定镜像的历史版本信息
3.logs打印容器中进程的运行日志

Guess you like

Origin blog.csdn.net/weixin_43313333/article/details/128823574