Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'docker ps' and 'docker-compose ps' commands give different result

docker ps is giving me a different output compared to docker-compose ps.

For example

docker ps

is not showing the same containers as

docker-compose ps

and vice-versa.

What is the reason for this?

I was thinking docker-compose is working on top of docker.

like image 727
Andreas Urbanczyk Avatar asked Nov 25 '16 15:11

Andreas Urbanczyk


People also ask

What is the difference between Docker compose and Docker compose?

The key difference between docker run versus docker-compose is that docker run is entirely command line based, while docker-compose reads configuration data from a YAML file. The second major difference is that docker run can only start one container at a time, while docker-compose will configure and run multiple.

What is the difference between Docker compose run and Docker compose start commands?

The run command acts like docker run -ti in that it opens an interactive terminal to the container and returns an exit status matching the exit status of the process in the container. The docker compose start command is useful only to restart containers that were previously created, but were stopped.

What does docker ps command do?

The docker ps command, which is available inside the container, is used to see the status of the process. This is similar to the standard ps command in the Linux environment and is not a docker ps command that we run on the Docker host machine.

What is the advantage of using Docker compose?

Docker Compose is a tool that was developed to help define and share multi-container applications. With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down.


2 Answers

docker ps lists all running containers in docker engine. docker-compose ps lists containers related to images declared in docker-compose file.

The result of docker-compose ps is a subset of the result of docker ps.

like image 126
andolsi zied Avatar answered Nov 15 '22 14:11

andolsi zied


docker ps - lists all running containers in Docker engine.

docker-compose ps - lists containers for the given docker compose configuration. The result will depend on configuration and parameters passed to docker-compose command.

Example

Start the containers with the following command:

docker-compose -p prod up -d

(-p in the command above defines the project name)

Running docker-compose ps won't list containers since the project name parameters is not passed:

docker-compose ps

Name   Command   State   Ports
------------------------------

Running docker-compose -p prod ps will list all containers:

     Name                   Command               State                       Ports
--------------------------------------------------------------------------------------------------------
dev_app_1        sh -c exec java ${JAVA_OPT ...   Up      0.0.0.0:5005->5005/tcp, 0.0.0.0:9001->9000/tcp
dev_database_1   docker-entrypoint.sh postgres    Up      0.0.0.0:5432->5432/tcp
dev_nginx_1      /docker-entrypoint.sh ngin ...   Up      0.0.0.0:8443->443/tcp, 0.0.0.0:8080->80/tcp
dev_pgadmin_1    /entrypoint.sh                   Up      443/tcp, 0.0.0.0:9100->80/tcp

The same goes if you define for example docker compose files with -f parameter.

like image 1
MarkoMilos Avatar answered Nov 15 '22 13:11

MarkoMilos