Get the App
SLTechnology News&Howtos  ›  Servers  › 

How do I get the ID of the Docker container process?

Shulou Source: shulou.com Published: 2022-06-02 15:38:43 09月22日 Update

Before we begin

In some cases, for example, if the system load is very high and docker stop cannot close a container (no response), you can find the host process ID based on the ID of the container process, and then kill the container (it is best to use volume data persistence, otherwise there is a risk of data loss in the container).

The procedure lists the current container docker ps-- format'{{.ID}} {{.Names}} 'CONTAINER ID NAMES1201281cb959 web425a6234df74 db to get the container process IDdocker inspect-f' {{State.Pid}} 'web9834 process information tail / proc/9834/cmdline; echo nginx: master process nginx-g daemon off; can also use the topsubcommand docker top web to kill the process ID if necessary, which is equivalent to forcing the container to be closed. Kill-9 9834Docker Container process

The content is extracted from

The relationship between Image and Container is like classes and instances in object-oriented programming. Mirrors are static definitions and containers are entities that mirror runtime. Containers can be created, started, stopped, deleted, paused, and so on.

A container is essentially a process, but unlike a process executed directly in the host, the container process runs in its own independent namespace. So the container can have its own root file system, its own network configuration, its own process space, and even its own user ID space.

Processes in the container run in an isolated environment and are used as if they were operating on a system independent of the host. This feature makes container-encapsulated applications more secure than running directly in the host.

Summary

Finally, let's summarize the knowledge points in the article.

The Docker container is essentially a process on the host. The container process ID is the host process ID because they are the same. If the Docker daemon responds normally, do not kill the process directly.

Reference article

Doker&k8s Qun [703906133]

Tags: Container process host run data space system host article mirror independent different same security necessary information content command entity instance Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn Huawei MySQL Microsoft