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 psdocker container ps
docker container ls
List both running and stopped containers
docker ps -adocker container ps -a
docker container ls -a
Show disk usage by container
docker ps -sdocker container ls -s
Filter and list containers based on STATUS
docker ps --filter status=runningdocker container ls --filter status=running
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 NAME
docker ps --filter "name=nginx"
docker container ls --filter "name=nginx"
Formatting: outputs the ID and Command entries separated by a colon (:) for all running containers:
docker container ls --format "{{.ID}}: {{.Command}}"Formatting: To list all running containers with their labels in a table format you can use:
docker container ls --format "table {{.ID}}\t{{.Labels}}"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
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 rm nginx
docker container stop proxy_nginx
docker container rm new_nginx_proxy
docker container stop nginx
Stop a running container and start it again
docker restart <CONTAINER_ID>docker container restart <CONTAINER_ID>
docker restart nginx
docker container restart nginx
Pause processes in a running container
docker pause <CONTAINER_ID>docker container pause <CONTAINER_ID>
docker pause nginx
docker container pause nginx
Unpause processes in a running container
docker unpause <CONTAINER_ID>docker container unpause <CONTAINER_ID>
docker unpause nginx
docker container unpause nginx
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
Kill a running container
docker kill <CONTAINER_ID>docker container kill <CONTAINER_ID>
docker kill nginx
docker container kill nginx
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
Hope this list of docker container commands will be helpful to some one in need.
Thanks You.
No comments:
Post a Comment