I'm trying to bring in other containers in run time- how does ps work to find the current container? Where does it look?
-
I have answered your question below, however, I implore that before you most another question on SO, please take a moment to review this StackOverflow guide on [How do I ask a good question](http://stackoverflow.com/help/how-to-ask). The last link I provided came from a simple SO search. Things that can be found in simple SO searches should not be someone else's question later ... the answer is already there. You may find that your question gets down-votes because of this. Thank you. – Michael M Dec 22 '15 at 18:35
-
Also, is there a reason you care about how `docker ps` does it, as opposed to how you could do it in your own tools? There *are* other approaches -- the Docker API is one, but inspecting cgroups is another. Providing at least some idea of your real-world use case in your question will help to ensure that you don't get answers that are technically correct but a poor choice for the task at hand. – Charles Duffy Dec 22 '15 at 18:51
1 Answers
Sound like you have 2 questions. To answer the first part, how it works, the basic answer is a client-server architecture: When you use docker ps
or docker ps -a
you are actually using the docker client which will send a request to the docker server instance which listens on a socket connection, although docker server can be started-up using an IP as well.
You can even connect to the docker server "remote API" without using the docker client.
To answer the question of where it looks: When the client relays the relevant request from your docker ps
command to the server (daemon), and the server simply reports which containers it's currently running and controlling. When you use docker ps -a
to see all containers, including those that are stopped (not running under the control of the docker daemon), the server will also check where it keeps it's stopped containers. Please see the this linked StackExchange article for more information.