I'm using docker. so docker is a process, not a VM. to check this. So I tried to run 'docker run --name mongo -d mongo', it works fine . then I checked the 'PID' using 'docker top mongo' it return the 'PID' details. then i tried 'ps aux' to see all process states. but I cannot see that mongo 'PID' in the list. why is that. I'm using mac with newest mac os.
-
4Since you're on the mac & the container is running in side a tiny Moby VM in HyperKit, you won't see you container running as a process in your terminal. This is running inside the HyperKit VM. In Linux, you can see the container running as the process via the `ps aux` command. – Janshair Khan Nov 15 '17 at 05:58
-
You might be following the Docker Mastery course on Udemy. If so, Bret Fisher explains in the Q&A for that video that he forgot to mention that for Mac you need to first connect to the Moby VM to see the mongo process. He says he plans to fix the video. https://www.bretfisher.com/docker-for-mac-commands-for-getting-into-local-docker-vm/ – Jason R Jan 05 '18 at 18:47
2 Answers
You need to docker exec to your mongodb container, running in your XHyve/HyperKit VM.
docker exec -it <containerID> bash
Then you can execute a ps, and see the mongodb pid there.
See as an example (on Mac) this article "How to use MongoDB & NodeJS with Docker".
As Matt adds in the comments:
You can also connect to the vm to see the real pid with
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
(as mentioned in "Where is /var/lib/docker on Mac/OS X")
-
You can also connect to the vm to see the real pid with `screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty` – Matt Nov 15 '17 at 06:13
-
@Matt Thank you. I have included your comment in the answer for more visibility. – VonC Nov 15 '17 at 08:29
As others have mentioned, when running on MAC, Docker is actually running in the backgound inside a VM and thus you will not be able to see the container process directly.
Moreover, even if you connect to the actual VM and check the PID for mongo container it will be different from the PID reported back when you run docker top mongo
.
This is due to PID namespaces that docker uses to isolate processes running inside the docker container. So don't rely on the PID to detect the process.

- 46,736
- 10
- 93
- 87