Thursday, 23 July 2020

Docker Container Commands


Docker is a platform for developers and sysadmins to build, run, and share applications with containers.

Below article will show different commands those can be used to manage docker containers. 


List running containers

docker ps
docker container ps
docker container ls

List running containers


List both running and stopped containers

docker ps -a
docker container ps -a
docker container ls -a

List both running and stopped containers


Show disk usage by container

docker ps -s
docker container ls -s

Show disk usage by container



Filter and list containers based on STATUS

docker ps --filter status=running
docker container ls --filter status=running

Filter and list containers based on STATUS


Filter and list containers based on EXITED

docker ps -a --filter 'exited=0'
docker container ls -a --filter 'exited=0'

Filter and list containers based on EXITED



Filter and list containers based on NAME

 docker ps --filter "name=nginx"
 docker container ls --filter "name=nginx"

Filter and list containers based on NAME



Formatting: outputs the ID and Command entries separated by a colon (:) for all running containers:

docker container ls --format "{{.ID}}: {{.Command}}"

Formatting: outputs the ID and Command entries separated by a colon (:) for all running containers:



Formatting: To list all running containers with their labels in a table format you can use:

docker container ls --format "table {{.ID}}\t{{.Labels}}"

Formatting: To list all running containers with their labels in a table format you can use:


Create a container from existing docker image without running it

docker create <IMAGE_NAME>
docker container create <IMAGE_NAME>

docker create nginx
docker container create --name nginx-proxy nginx

Create a container from existing docker image without running it


Rename existing container name

docker rename <EXISTING_CONTAINER_NAME> <NEW_CONTAINER_NAME>
docker container rename <EXISTING_CONTAINER_NAME> <NEW_CONTAINER_NAME>

docker container rename nginx-proxy new_nginx_proxy
docker container ls -a

Rename existing container name



Delete a container

docker rm <CONTAINER_ID>

docker rm nginx
docker container stop proxy_nginx
docker container rm new_nginx_proxy

Delete a container



Start docker container

docker start <CONTAINER_ID>
docker container start <CONTAINER_ID>

docker start nginx
docker container start nginx

Start docker container



Stop a running container

docker stop <CONTAINER_ID>

docker container stop nginx

Stop a running container


Stop a running container and start it again

docker restart <CONTAINER_ID>
docker container restart <CONTAINER_ID>

docker restart nginx
docker container restart nginx

Stop a running container and start it again


Pause processes in a running container

docker pause <CONTAINER_ID>
docker container pause <CONTAINER_ID>

docker pause nginx
docker container pause nginx

Pause processes in a running container


Unpause processes in a running container

docker unpause <CONTAINER_ID>
docker container unpause <CONTAINER_ID>

docker unpause nginx
docker container unpause nginx

Unpause processes in a running container


Block a container until others stop (after which it prints their exit codes)

docker wait <CONTAINER_ID>
docker container wait <CONTAINER_ID>

docker wait nginx
docker container wait nginx

Block a container until others stop (after which it prints their exit codes)


Kill a running container

docker kill <CONTAINER_ID>
docker container kill <CONTAINER_ID>

docker kill nginx
docker container kill nginx

Kill a running container


Attach local standard input, output, and error streams to a running container

docker attach <CONTAINER_ID>
docker container attach <CONTAINER_ID>

docker run -itd --name alpine alpine
docker attach alpine

Attach local standard input, output, and error streams to a running container


Hope this list of docker container commands will be helpful to some one in need. 

Thanks You.



No comments:

Post a Comment