How to know a process is running under docker

I may be asking a very beginner level question but I need a way to distinguish process under docker and that under non-docker in a box. The ‘ps’ command command output gives me a feeling that process is running in linux box and cannot confirm if same is under hood of docker.

In the same context is it possible / feasible that process under docker be started with docker root file system.

  • Docker routing/reverse proxy issue, can't curl other container
  • Setting up salt-master in Docker container: The ports are not available to bind error
  • Docker Toolbox - Localhost not working
  • How to get docker to work within vagrant?
  • Docker Alpine /bin/sh apk not found
  • Kubernetes pod not binding volumes to container
  • Is the same feasible or there any other solution for same?

  • docker suspend and resume using criu
  • bash: How do I write a shell script to sftp a mongodump from a MongoDB Docker container inside a DigitalOcean droplet to backup the MongoDB database?
  • What is the proper way of deploying versioned applications with docker?
  • building docker image from dockerfile
  • Docker 1.7 consuming more space than Docker 1.5 for images
  • How can I restrict ports to a host created by docker-machine?
  • 3 Solutions collect form web for “How to know a process is running under docker”

    You can identify Docker process via the process tree on the Docker host.

    The parent process to 2924(haproxy) is 2902
    The parent process to 2902(haproxy-start) is 2881
    2881 will be docker-container which is managed by a dockerd process

    To view your process listing in a tree format use ps -ejH or pstree (available in the psmisc package)

    To get a quick list of whats running under dockerd

    / # pstree $(pgrep dockerd)
            |                 |                 `-8*[{docker-containe}]
            |                 |-docker-containe-+-sinopia-+-4*[{V8 WorkerThread}]
            |                 |                 |         |-{node}
            |                 |                 |         `-4*[{sinopia}]
            |                 |                 `-8*[{docker-containe}]
            |                 |-docker-containe-+-node-+-4*[{V8 WorkerThread}]
            |                 |                 |      `-{node}
            |                 |                 `-8*[{docker-containe}]
            |                 |-docker-containe-+-tinydns
            |                 |                 `-8*[{docker-containe}]
            |                 |-docker-containe-+-dnscache
            |                 |                 `-8*[{docker-containe}]
            |                 |-docker-containe-+-apt-cacher-ng
            |                 |                 `-8*[{docker-containe}]
            |                 `-20*[{docker-containe}]

    Show the parents of a PID (-s)

    / # pstree -aps 3744 
      `-dockerd,1721 --pidfile=/run/ -H unix:///var/run/docker.sock --swarm-default-advertise-addr=eth0
          `-docker-containe,1728 -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim ...
              `-docker-containe,3711 8d923b3235eb963b735fda847b745d5629904ccef1245d4592cc986b3b9b384a...
                  `-java,3744 -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp/zookeeper/bin/../build/cl

    Show all children of docker, including namespace changes (-S):

    / # pstree -apS $(pgrep dockerd) 
    dockerd,1721 --pidfile=/run/ -H unix:///var/run/docker.sock --swarm-default-advertise-addr=eth0
      |-docker-containe,1728 -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim ...
      |   |-docker-containe,3711 8d923b3235eb963b735fda847b745d5629904ccef1245d4592cc986b3b9b384a...
      |   |   |-java,3744,ipc,mnt,net,pid,uts -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp/zookeeper/bin/../build/cl
      |   |   |   |-{java},4174
      |   |   |   |-{java},4175
      |   |   |   |-{java},4629
      |   |   |   `-{java},4632
      |   |   |-{docker-containe},3712
      |   |   `-{docker-containe},4152
      |   |-docker-containe,3806 49125f8274242a5ae244ffbca121f354c620355186875617d43876bcde619732...
      |   |   |-sinopia,3841,ipc,mnt,net,pid,uts                                                           
      |   |   |   |-{V8 WorkerThread},4063
      |   |   |   |-{V8 WorkerThread},4064
      |   |   |   |-{V8 WorkerThread},4065
      |   |   |   |-{V8 WorkerThread},4066
      |   |   |   |-{node},4062
      |   |   |   |-{sinopia},4333
      |   |   |   |-{sinopia},4334
      |   |   |   |-{sinopia},4335
      |   |   |   `-{sinopia},4336
      |   |   |-{docker-containe},3814
      |   |   `-{docker-containe},4038
      |   |-docker-containe,3846 2a756d94c52d934ba729927b0354014f11da6319eff4d35880a30e72e033c05d...
      |   |   |-node,3910,ipc,mnt,net,pid,uts lib/dnsd.js
      |   |   |   |-{V8 WorkerThread},4204
      |   |   |   |-{V8 WorkerThread},4205
      |   |   |   |-{V8 WorkerThread},4206
      |   |   |   |-{V8 WorkerThread},4207
      |   |   |   `-{node},4203

    The command lxc-ls and the command lxc-ps may be installable on your Linux distribution. This will allow you to list the running LXC containers and the processes running within those containers respectively. You should be able to link the output from lxc-ls to lxc-ps using streams and get a list of all containerized processes.

    The big caveat is that you specified Docker and not every Docker instance is running on LXC nor is it necessarily a localhost process. Docker defines an API that can be called to list remote Docker instances, so this technique will not help with enumerating processes on remote machines as well.

    In windows docker behave little bit different.
    It’s processes are not run as child of parent process, but running as separate process on the host.

    They can be viewed by (for example), powershell, like

    Get-Process powershell

    For example, getting processes on the host when running microsoft/iis container will include additional powershell process (since ms/iis container runs powershell as a main executable process).

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.