Docker Cheat Sheet: by Devops G
Docker Cheat Sheet: by Devops G
https://www.facebook.com/groups/devopsg/
→ docker ps -a (this lists all containers either stopped or in running condition)
→ docker ps -l (this is used to show the latest docker container created or modified)
→ docker images (Lists all available image in host OS in which docker engine is installed)
-→ docker run -it -d image_name (Runs a command in an isolated container [ i=interactive, t=tty means for
terminal , d= for daemon or background process or in detached mode])
https://www.facebook.com/groups/devopsg/
→ docker start container_id (Starts the stopped containers)
→ docker commit (Creates a new image from the current changed state of the container)
https://www.facebook.com/groups/devopsg/
→ docker info (Shows system-wide information)
→ docker inspect (Finds system-level information about docker containers and images)
https://www.facebook.com/groups/devopsg/
→ docker rm container_id ( Remove stopped containers)
→ docker rmi $(docker images -q) (this deletes all docker images for which no container is running)
→ docker rmi -f $(docker images -q) (this deletes all docker images forcefully)
https://www.facebook.com/groups/devopsg/
➔ docker rm -f $(docker ps -a -q)
→ docker save image_name -o new_name.tar ( the new image name extension should be tar and this saves any
image to the tar format only the condition is image should be available on host os)
→ docker load -i new_name.tar (this will again create the image which we saved in last command, this mainly used
for sharing a docker image from one host to another host)
Similar to image we can use export and import command for saving container as .tar file and converting that .tar
file to docker image as shown below: -
→ docker export my_container -o my_container.tar (this will save our container in .tar file)
https://www.facebook.com/groups/devopsg/
→ docker import my_container.tar (this will create the image which was saved as tar in last command but this image
will be treated as filesystem as this doesn’t contain all the layers or history which we had seen in earlier command of
docker load)
Ans→ The main difference is docker save/load with image does preserve the image history. Whereas
docker export/import with container flattens the image by removing all the history of the container.
https://www.facebook.com/groups/devopsg/
→ docker logs container_id (this will give the logs of the container)
→ docker stats container_id (this will give the resource usage (CPU, RAM,network i/o) of mentioned container)
➔ docker stats (this will give resource usage of all available container in host OS)
→ docker stats container_id --no-stream (this will show the resource without streaming)
→ docker top container_id (this will display top process running in a container)
→ docker build -t myimage:version dockerfile_path (this will build the docker image from docker file)
→ docker tag existing_image:tag_name new_image_name:new_tag_name ( this will create an image with the
desired image name and tag name)
https://www.facebook.com/groups/devopsg/
Note:- for port mapping -p is for user defined port no. and -P is for random port no. which will be assigned by OS
But when we uses -P docker randomly assigns any free port to the port used by nginx i.e 80:-
Docker volume:-
https://www.facebook.com/groups/devopsg/
In below snap we can see by default no docker volume is existing:-
https://www.facebook.com/groups/devopsg/
docker volume –help (this command gives all the available options to be applied with docker volume)
Ans→ docker volume rm removes only docker volume of mentioned name whereas docker prune deletes all existing
docker volume .
For more live training, sessions, discussions on docker and all devops tools join us at our facebook page “DevOps G”
https://www.facebook.com/groups/devopsg/