Show Menu
Cheatography

Docker Commands

Basic Docker Commands

docker ps
List of live containers
docker ps -a
List all containers
docker info
Retrieves docker config­uration
docker version
Retrieves docker versioning
docker build -t <Im­age­>:<­Tag> .
Builds a docker Image from Dockerfile or container
docker push <Im­age­_Na­me>­:<T­ag>
Pushes the image to the repo
docker pull<I­mag­e_N­ame­>:<­Tag>
Pulls the image from the repo

Container Commands

docker inspect <Container>
Inspect a container
docker stats <Co­nta­ine­r>
Live data stream from container
docker logs <Co­­nt­a­i­ne­­r>
Retrieves the containers logs
docker run <Co­nta­ine­r>
Run container
docker kill <Co­nta­ine­r>
Kill a running container
docker start <Co­nta­ine­r>
Start container
docker stop <Co­nta­ine­r>
Stop a running container
docker restart <Co­nta­ine­r>
Restarts the container
docker rm <Co­nta­ine­r>
Remove container
docker port <Co­nta­ine­r>
Lists the port mapping of the container
docker pause <Co­nta­ine­r>
Suspends all the processes in the container
docker unpause <Container>
Un-sus­pends all the processes in the container
<Co­nta­ine­r> can be replaced with the containers ID or NAME

Volume Commands

docker volume ls
List volumes
docker volume inspect <Vo­lum­e>
Inspect volume
docker volume create <Vo­lum­e>
Create volume
docker volume rm <Vo­lum­e>
Removes a volume
<Vo­lum­e> can be replaced with the volume ID or NAME

Misc. Commands

docker cp <Co­nta­ine­r>:­<so­urc­e_p­ath> <de­st_­pat­h>
Copy from container to host
docker cp <source_path> <Container>:<dest_path>
Copy from host to container
docker exec -ti <Co­nta­ine­r> <En­try­poi­nt>
Executes the terminal of a live container
 

Options Keywords

-p, –-publish
Host to container port mapping
--publ­ish-all
Publish all ports
--expose
Expose container port
-d, –-detach
Run in background
-e, –-env
set env vars
-v, --volume
Mount files or direct­ories
-i, --inte­ractive
-t, --tty
exec
Run a new command in a container
cp
copy path
These options keywords can be add to most docker commands

Image Commands

docker images
List images
docker run <Im­age>
runs the image
docker create <Im­age­>:<­Tag>
Create image
docker rmi <Im­age>
Remove image
docker save <Im­age>
Saves images to a tar archive

Network Commands

docker network ls
List networks
docker network inspect <Ne­two­rk>
Inspect a network
docker network create <Ne­two­rk>
Create a network
docker network rm <Ne­two­rk>
Removes a network
docker network connect <Ne­two­rk> <Co­nta­ine­r>
Connect a container to the network
docker network connect --ip <IP> <Ne­two­rk> <Co­nta­ine­r>
Specify the ip address of container interface
docker network disconnect <Ne­two­rk_­Nam­e> <Co­nta­ine­r>
Disconnect container from network
<Ne­two­rk> can be replaced with the network ID or NAME
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets