Show Containers
docker psExample output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1b2c3d4e5f6 nginx:latest "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:80->80/tcp webserver
b2c3d4e5f6a1 redis:alpine "docker-entrypoint.s…" 3 hours ago Up 3 hours 0.0.0.0:6379->6379/tcp redis-cacheDocker Swarm
docker service ls
docker service ps myservice
docker psExample output — docker service ls:
ID NAME MODE REPLICAS IMAGE PORTS
x1y2z3a4b5c6 myservice replicated 3/3 nginx:latest *:80->80/tcp
d4e5f6g7h8i9 redis replicated 1/1 redis:alpineExample output — docker service ps myservice:
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE
t1u2v3w4x5y6 myservice.1 nginx:latest worker1 Running Running 10 minutes ago
u2v3w4x5y6z7 myservice.2 nginx:latest worker2 Running Running 10 minutes ago
v3w4x5y6z7a8 myservice.3 nginx:latest worker3 Running Running 10 minutes agoDocker Compose
Go to the compose folder and run:
docker-compose ps
docker psExample output — docker-compose ps:
Name Command State Ports
---------------------------------------------------------------------------------
myapp_web_1 nginx -g daemon off; Up 0.0.0.0:80->80/tcp
myapp_db_1 docker-entrypoint.sh postgres Up 5432/tcp
myapp_redis_1 docker-entrypoint.sh redis ... Up 6379/tcpDocker Compose Stack
Go to the compose folder and run:
docker stack ps mystackExample output:
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE
a1b2c3d4e5f6 mystack_web.1 nginx:latest node1 Running Running 5 minutes ago
b2c3d4e5f6a1 mystack_db.1 postgres:14 node2 Running Running 5 minutes ago
c3d4e5f6a1b2 mystack_redis.1 redis:alpine node1 Running Running 5 minutes agoNote:
docker pswill not show containers running in a stack.
Show Ports in Use
sudo lsof -i TCP:9090
sudo lsof -i | grep 9090
less /etc/servicesExample output — sudo lsof -i TCP:9090:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
prometheus 1234 root 7u IPv4 98765 0t0 TCP *:9090 (LISTEN)Example output — sudo lsof -i | grep 9090:
prometheus 1234 root 7u IPv4 98765 0t0 TCP *:9090 (LISTEN)
chrome 5678 user 23u IPv4 11223 0t0 TCP localhost:52101->localhost:9090 (ESTABLISHED)(Visited 1 times, 1 visits today)

