0

I'm kind of new to Docker and Linux. I was wondering what does "running in background" means when it comes to containers since I can't find a process that relates to a background RUNNING container.

I ran htop filtered on docker and started 2 containers:

  1. docker run nginx --> As I expected, a process appeared in htop (child of the shell who launched it)
  2. docker run -d nginx --> Nothing appeared here (the container IS running though)

I couldn't find any explanation (I'm probably just not looking where I should...). What is happening here ?

EDIT:

I eventually figured out the "issue" which, as usual, lay between my chair and my keyboard: I'm running a headless linux VM on macOS and it didn't occur to me (until now (╬ಠ益ಠ)) that I wasn't launching my commands on the VM but directly on my host OS.

So under the hood docker on macOS was using its own linux VM and my htop command only listed the one linked to an opened 'host' terminal...

See How to retrieve docker container name from pid of docker exec on the host (MacOS)

amoutaux
  • 1
  • 3
  • `since I can't find a process that relates to a background RUNNING container.` where and how do you search? – KamilCuk Jun 28 '21 at 08:46
  • Hi @KamilCuk, as I stated I'm using `htop` and its `Filter` function. I filtered using the keywords "docker" and "nginx" (not simultaneously obviously) – amoutaux Jun 28 '21 at 09:01
  • as what user? use https://stackoverflow.com/questions/34878808/finding-docker-container-processes-from-host-point-of-view – KamilCuk Jun 28 '21 at 09:07
  • 1
    Thanks for the link, it did help me in the end :). I edited my post. I blame myself for not specifying right at the start that I was working on linux but under MacOS, i think someone would've spotted my mistake right away... I raised a duplicate flag – amoutaux Jun 28 '21 at 09:45
  • "lied"? I think the word you wanted was "lay". – jbruni Nov 27 '22 at 23:31
  • It was obviously – amoutaux Feb 13 '23 at 15:24

1 Answers1

1

Docker containers are, in the end, just processes. It's possible for a container to die though.

If you do docker run -d nginx it'll print out a long hexadecimal string. That's the ID of the new container. You can run docker logs <container-id> to get the logs, e.g. docker logs 123456. You don't need the whole ID, just the first few characters will work.

You can see running containers using docker ps, and see all containers (alive and dead) using docker ps -a.

Itamar Turner-Trauring
  • 3,430
  • 1
  • 13
  • 17
  • Thanks for your time, but I can't see how that answers my question ^^'. My point is: `docker run nginx` seems to appear in `htop` as a process while `docker run -d nginx` does not. I'm not killing the containers, they both appear when I `docker container ls` (without the `-a`, which proves they are indeed running) – amoutaux Jun 24 '21 at 15:50
  • `nginx` is probably dying. I can't tell you why, but `docker logs` might be able to! – Itamar Turner-Trauring Jun 24 '21 at 15:51
  • Both containers are running (`docker container ls` - without `-a` - lists both, I can interact with them, access logs, etc). I added the logs to my post in case it helps – amoutaux Jun 24 '21 at 16:03