Docker Commands Cheat Sheat

Posted on 02nd May 2018

Managing Docker Images

docker image lsList docker images. You can also use the command docker images
docker image inspect some_imageDispaly detailed information about the specified image.
docker image rm some_imageRemove one or more images.
docker image history some_imageShow history of an image.
docker image pruneRemove dangling images.
docker rmi $(docker images -a -q)Remove all Docker images.
docker run some_imageStart a Docker container from the specified image.
docker run some_image -d -it --name container_nameStart a Docker container from image.
-d option is to run the container in detached mode. -it option is for interactive mode.
--name option is used to specify a name to identify the container.
docker build -t name:tagBuild an image from the Dockerfile.
Note: some_image can be name, id or prefix of an image.

Managing Docker Containers

docker container lsList running Docker containers.
docker container ls -aList all Docker container including containers that exited.
docker container inspect some_containerDisplay detailed information of a specified container.
docker container attach some_containerAttach standard input, output and error streams to a running container. To detach, press CTRL-p CTRL-q
docker container commit -p some_container image_name:tagCreate a new image with the file changes from a running container.
-p option is to pause the container during commit.
docker container stop some_containerStop a running container.
docker container rm some_containerRemove a container.
docker container cp source_path destination_pathCopy files and folders between local filesystem and a container. The container file path must be prefixed by the container name in the format container_name:/file/path

docker container stats some_containerDisplay resource usage statistics of a running container. If container name is omitted, resource usage of all containers are displayed.
docker container logs some_containerDisplay a container's logs.
docker container restart some_containerRestart a container.
docker container rename some_container new_container_nameRename a container.
docker container kill some_containerKill one or more containers.
docker container topDisplay running processes in a container.
docker container start some_containerStart a container that was stopped before.
docker container exec some_container commandRun a command in a container that is running.
The --it option can be used to run the command in interactive mode.
Note: some_container can be name, id or prefix of a container.

Docker Network Commands

docker network lsList available networks.
docker network inspect network_nameDisplay detailed information about the specified network
docker network connect network_name container_nameConnect a container to the specified network. You can use the --ip option to specify the ip address to be assigned to the container.
docker network disconnect network_name container_nameDisconnect a container from a network.
docker network create -d driver network_nameCreate a network with the specified name. The drive can be bridge or overlay. Default is bridge if -d option is omitted.

Docker Registry Commands

docker pull Image_name:tagPull a Docker image or repository from the Docker Hub registry.
docker push Image_name:tagPush an image or repository to Docker Hub registry
docker login -u UsernameLogin to Docker Hub registry.
docker logoutLogout from Docker Hub registry.

General Docker Commands

docker --versionDisplay docker version.
docker infoShow system wide information of the Docker installation.
dockerList all Docker commands.

Post a comment


Nothing the first to share wisdom.