简体   繁体   English

如何知道哪些 systemd 服务正在运行 docker 容器

[英]How to know which systemd services are running the docker containers

Few docker containers on Linux auto restarts when stopped. Linux 上的几个 docker 容器在停止时会自动重新启动。 How can we know which specific systemd services are running these containers?我们如何知道哪些特定的 systemd 服务正在运行这些容器? Few steps followed:接下来的几个步骤:

"docker ps -a" -- lists all containers with containerID Step 1 "docker ps -a" -- 列出所有具有 containerID 的容器 步骤 1

"systemctl list-units" -- list all the units Step 2 "systemctl list-units" -- 列出所有单元 Step 2

"systemctl status <Unit -Name>" --Gives location & further details about service “systemctl status <Unit -Name>”——提供位置和有关服务的更多详细信息

Tried stopping few service units which I believed were responsible for container restarts but it didn't helped.尝试停止一些我认为负责容器重启的服务单元,但没有帮助。 below Commands were followed:遵循以下命令:

"systemctl stop <Unit -Name >" “systemctl stop <单位-名称>”

"systemctl disable <Unit - Name>" “systemctl disable <单位-名称>”

"rm -rf /etc/systemd/system/ <Unit -Name>" -- removed those specific unit folders as from Step 2 above "rm -rf /etc/systemd/system/ <Unit -Name>" -- 从上面的步骤 2 中删除那些特定的单元文件夹

But the Units and containers still show up as in Step 1 & 2 above.但是单元和容器仍然显示在上面的第 1 步和第 2 步中。 How to stop and remove these containers?如何停止和移除这些容器?

Are you sure that systemd services restart the containers?您确定 systemd 服务会重新启动容器吗? Maybe there is a restart policy.也许有重启政策。 Check it with:检查它:

docker inspect container_name | grep -A10 RestartPolicy

To remove the container:要移除容器:

docker rm -f container_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM