Docker common container problems

Docker common container problems

Docker is easy to learn


1. What is Docker?

Docker is a technology that enables applications to be packaged in any environment. The packaged thing is called an image.

2. After the container exits, it cannot be viewed through the docker container ls command. Will the data be lost?

After the container exits, it will be in the terminated (exited) state. At this time, you can view it through docker container ls -a, and the data in it will not be lost.
The code is as follows (example):

docker container ls -a 

It can also be started with the docker start command. Only deleting the container will clear all data.

 docker start 

3. How to stop all running containers?

docker stop $(docker container ls -q) 

4. How to clean up the stopped containers in batches?

docker container prune

4. How to obtain the PID information of a container?

docker inspect --format '{
    
    { .State.Pid }}' <CONTAINER ID or NAME>

5. How to obtain the IP address of a container?

docker inspect --format '{
    
    { .NetworkSettings.IPAddress }}' <CONTAINER ID or NAME>

6. How to assign a fixed IP address to the container?

docker network create -d bridge --subnet 172.0.0.1/16 my-net

docker run --network=my-net --ip=127.0.0.1 -itd --name=my-container busybox

7. How to temporarily exit the terminal of an interacting container without terminating it?

Ctrl-p 
Ctrl-q

8. When using the docker port command to map the port of the container, the system reports the error "Error: No public port '80' published for xxx"?

* 创建镜像时 Dockerfile 要通过 EXPOSE 指定正确的开放端口;
* 容器启动时指定 PublishAllPort = true。

9. Can multiple application processes run simultaneously in a container?

Running multiple application processes in the same container is generally not recommended. If you have similar requirements, you can manage the running processes through some additional process management mechanisms, such as supervisord.

10. How to control the share of system resources (CPU, memory) occupied by containers?

When using the docker create command to create a container or using docker run to create and start a container, you can use the -c|–cpu-shares[=0] parameter to adjust the weight of the container used by the CPU; use -m|–memory[=MEMORY] parameter to adjust the size of the memory used by the container.

11. Docker starts to report Error response from daemon

Error response from daemon: driver failed programming external connectivity on endpoint gloomy_kirch

systemctl restart firewalld
systemctl restart docker

Summarize

Don't be afraid if you encounter Docker problems, write it down, and forget it next time

Hope this blog will be useful to you. I am the King of Light, and I speak for myself.

Guess you like

Origin blog.csdn.net/moer0/article/details/123141419