To get container ID you can use:

cat /proc/<process-pid>/cgroup

Then to convert the container ID to docker container name:

docker inspect --format '{{.Name}}' "${containerId}" | sed 's/^\///'

以下是例子

[root@nodejs1 ~]# cat /proc/68069/cgroup
11:pids:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
10:hugetlb:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
9:perf_event:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
8:devices:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
7:freezer:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
6:net_prio,net_cls:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
5:cpuacct,cpu:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
4:cpuset:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
3:blkio:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
2:memory:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
1:name=systemd:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
[root@nodejs1 ~]# docker inspect --format '{{.Name}}' "f66f" | sed 's/^\///'
shebao.1.hx50qn3yaahmm03nybc1fwcyr
01-02 23:10