'docker ps' and 'docker-compose ps' commands give different result
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
.
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.