Docker: run
3 min readDec 8, 2020
Docker is a tool designed to make it easier to build, test, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries, system tool, code and runtime, and deploy it as one package.
Here is the list of most used commands that will make developers' life easier.
# check docker version
docker version
# view system wide Information
docker info
# run container (simple)
docker run <image name> // e.g.
docker run hello-world
# run container (simple++)
docker run <image name> <command>// e.g.
docker run busybox ls
# listing running containers
docker ps
# listing all containers (running and exited)
docker ps -a
# create container
docker create <image name>
# create named container
docker create --name <name> <container id>
# start a container
docker start <image name>
# stop container
docker stop <container id>docker kill <container id>
# stop all running containers
docker stop $(docker ps -a -q)
# restart container
docker restart <container id>
# pausing a running container
docker pause <container id>
# resuming a paused container
docker unpause <container id>
# remove stopped containers
docker system prune
# deleting container
docker rm <container id>
# delete all existing containers
docker rm $(docker ps -a -q)
# rename container
docker rename <container name> <new container name>
# get logs
docker logs <container id>
# get live logs
docker logs -f <container id>
# execute command in running container
docker exec -it <container id> <command>
# attaching to container console
docker attach <container id>
# update the configuration of a container
docker update <container id>
# look for changes in a container
docker diff <container id>
# export container to tar file
docker export <container id> -o <tar file>
# import container from tar file
docker import <tar file>
# copying contents between container and the file system
docker cp <container id>:/<source> <destination>
# list real-time events
docker events <container id>
# show port mapping
docker port <container id>
# show running processes
docker top <container id>
# get containers’ resource usage statistics
docker stats
# get containers’ resource usage statistics without live streaming
docker stats --no-stream
# create image
docker build .
# create image with different Dockerfile
docker build -f <dockerfile>
# create image out of container
docker commit <container id> <image name>
# tag image
docker build -t <docker id>/<project>:<tag> .
# pull docker image
docker pull <image name>
# pushing image to dockerhub
// prerequisite
docker logindocker image push <image name>
# listing images
docker images
# remove image
docker image remove <image name>
# delete all existing images
docker rmi $(docker images -q -a)
# search docker images
docker search <image name>
# save docker image to a tar file
docker save <image name> -o <tar file>
//or
docker save <image name> > <tar file>
# load docker image from tar file
docker load -i <tar file>
// or
docker load < <tar file>
# display history of docker image
docker history <image name>
# create a docker volume
docker volume create <volume name>
# remove a docker volume
docker volume rm <volume name>
# inspect a docker volume
docker volume inspect <volume name>
# list all docker volumes
docker volume ls
# creating a docker network
docker network create <network name>
# connecting a container to a network
docker network connect <network name> <container name>
# disconnecting a container from a network
docker network disconnect <network name> <container name>
# inspecting a network
docker network inspect <network name>
# list all docker networks
docker network ls
# remove a docker network
docker network rm <network name>
# delete all unused docker networks
docker network prune