How can I see which user launched a Docker contain

2019-05-13 06:38发布

I can view the list of running containers with docker ps or equivalently docker container ls (added in Docker 1.13). However, it doesn't display the user who launched each Docker container. How can I see which user launched a Docker container? Ideally I would prefer to have the list of running containers along with the user for launched each of them.

标签: docker
3条回答
相关推荐>>
2楼-- · 2019-05-13 06:55

You can try this;

docker inspect $(docker ps -q) --format '{{.Config.User}} {{.Name}}'

Edit: Container name added to output

查看更多
Fickle 薄情
3楼-- · 2019-05-13 06:57

If you are used to ps command, running ps on the Docker host and grep with parts of the process your process is running. For example, if you have a Tomcat container running, you may run the following command to get details on which user would have started the container.

ps -u | grep tomcat 

This is possible because containers are nothing but processes managed by docker. However, this will only work on single host. Docker provides alternatives to get container details as mentioned in other answer.

查看更多
祖国的老花朵
4楼-- · 2019-05-13 06:59
 ps -aux | less

Find the process's name (the one running inside the container) in the list (last column) and you will see the user ran it in the first column

查看更多
登录 后发表回答