Docker Useful Commands

Docker Useful Commands

July 24, 2021 1 By Nam Vu


#Create a container from an image
docker container create my_repo/my_image:my_tag
docker container create -a STDIN my_image
#Start an existing container
docker container start my_container
#Create a new container and start it
docker container run my_image
docker container run -i -t -p 1000:8000 –rm my_image
docker container run -d my_image
#List running containers
docker container ls
docker container ls -a -s
#See lots of info about a container
docker container inspect my_container
#Print a container’s logs
docker container logs my_container
#Stop one or more running
docker container stop my_container
#Kill a running container
docker container kill my_container
#Kill all running containers
docker container kill $(docker ps -q)
#Delete one or more containers
docker container rm my_container
#Delete all containers that are not running
docker container rm $(docker ps -a -q)

#Build a Docker image
docker image build -t my_repo/my_image:my_tag
#Push an image to a registry
docker image push my_repo/my_image:my_tag
#List your images
docker image ls
#Display an image’s intermediate images
docker image history my_image
#Delete the specified image
docker image rm my_image
#Delete all images
docker image rm $(docker images -a -q)

#List info about your Docker Client and Server versions
docker version
#Log in to a Docker registry
docker login
#Delete all unused containers, unused networks, and dangling images
docker system prune
docker system prune -a –volumes