Docker User Guide: A Quick Reference
Are you finding difficulty remembering all the commands that you need in order to work with Docker?
Guys, don’t worry! This Docker cheat sheet will give you a quick reference to the basics of Docker that you must know to get started with it.
Watch this Docker Tutorial for Beginners video:
At Intellipaat, we support our learners with a handy reference, that’s the reason we have created this cheat sheet. It is designed for those who have already started learning Docker but needs a handy reference to recall the concepts that they have learned.
The Docker tool was introduced to make it easier for developers to create, deploy, and run applications using containers. Containers provision the developers with the packaging of their applications, together with all important components they require such as libraries and other dependencies, and shipping of them all out as a single package. This assures the developers that their applications can be run on any other machine.
We will start this tutorial by understanding the Docker architecture and the main aspects in it, and then we will continue with the important commands required for the Docker operations, such as Docker installation, build, push, run, ship, clean up, and the interaction with the container.
Become a master of DevOps by enrolling in this online DevOps Training in London!
DevOps architecture consists of five main entities, namely, registry, image, container, daemon, and client.
- Registry: It hosts public and official images. The Docker registry that we use is Docker Hub.
- Image: It can be downloaded from the registry directly or implicitly when starting a container.
- Container: It is basically the instance of an image. Multiple containers can exist for a single image.
- Docker daemon: A daemon creates, runs, and monitors containers, along with building and storing images.
- Client: A client talks to Docker daemon via http.
Join the Best DevOps Course in New York to get a clear understanding of DevOps!
Orchestration is used for managing a container’s life cycle, especially in dynamic environments. It is used for controlling and automating many tasks for containers.
There are many Docker orchestration tools such as Docker Swarm, Kubernetes, etc. In this tutorial, we’re elucidating Docker Swarm commands. Let’s check out the commands used for Docker orchestration.
Learn more about DevOps in this DevOps Training in Sydney and get ahead in your career!
- To initialize the swarm mode and listen to a specific interface:
Docker swarm init --advertise-addr 10.1.0.2
- To join an existing swarm as a manager node:
Docker swarm join --token<manager-token> 10.1.0.2:2377
- To join a swarm as a worker node:
Docker swarm join --token<worker-token> 10.1.0.2:2377
- To list all nodes in the swarm:
Docker node ls
- To create a service from an image on the existing port and deploy three instances:
Docker service create --replicas 3 -p 80:80 name -webngix
- To list services running in a swarm:
Docker service ls
- To scale a service:
Docker service scale web=5
- To list the tasks of a service:
Docker service ps web
Equip yourself with these Top DevOps Interview Questions and Answers to ace your career!
The build command is used for building images from a Docker file. Let’s now check out some of the essential Docker build commands.
- To build an image from the Docker file and tag it:
Docker build -t myapp :1.0
- To list all the images that are locally stored:
- To delete an image from the Docker Store:
Docker rmi alpine: 3.4
Do you have queries related to DevOps? Visit our DevOps Community and get your queries clarified from the DevOps experts!
The run command is used for creating a container from a specified image. Check out the below-listed run commands.
- To create and run a command:
Docker run --name container_name docker_image
- -d: To detach a container on start
- -rm: To remove a container once it stops
- -p: To publish the host IP and the host port to the container port
- -v: To define and share the volume across containers
- –read-only: To set to the read-only permission
Docker gives us the capability of shipping our application container anywhere, on any platform. Let’s check out some commands used for it.
- To pull an image from the registry:
Docker pull alpine:3.4
- To retag a local image with a new image name:
Docker tag alpine:3.4 myrepo/ myalpine:3.4
- To log in to the registry:
Docker login my.registry.com:8000
- To push an image to the registry:
Docker push myrepo/ myalpine:3.4
Interested in becoming a DevOps expert? Visit DevOps Course in Toronto and enroll today!
To prevent wasting resources, we must know how to clean up. In this Docker cheat sheet tutorial, next, a few essential clean up commands are provided.
- To clean an unused/dangling image:
Docker image prune
- To remove an image that is not used in a container:
Docker image prune -a
- To prune the entire system:
Docker system prune
- To leave a swarm:
Docker swarm leave
- To remove a swarm:
Docker stack rm stack_name
- To kill all running containers:
Docker kill $ (docker ps -q)
- To delete all stopped containers:
docker rm $(docker ps -a -q)
- To delete all images:
docker rmi $(docker images -q)
Let’s now take a sneak peek at the commands used to view the running services, to run the services, to view all service logs, and to scale the services.
- To list all services running in a swarm:
Docker service ls
- To see all running services:
Docker stack services stack_name
- To see all service logs:
Docker service logs stack_name service_names
- To scale a service across qualified nodes:
Docker service scale stack_name_service_name= replicas
Interested in getting an industry-recognized certification in DevOps? Enroll in Intellipaat’s DevOps Course in Bangalore today!
Interaction with a Container
Let’s check out how to make an interaction with a container in Docker.
- To run a command in a container:
Docker exe -ti container_name command.sh
- To follow container logs:
Docker logs -ft container name
- To save a running container as an image:
Docker commit -m “commit message” -a “author” container_name username/image_name: tag
DevOps Engineers are among the highest paid professionals in the technology domain. So why wait? Join the next batch of the DevOps Training in Hyderabad!
Some of the important terms to know about while using Docker containers are listed below:
- Layer: Read-only files to provision the system
- Image: Read-only layer that is the base of an image
- Container: A runnable instance of the image
- Registry/hub: A central place where images reside
- Docker machine: A VM to run Docker containers
- Docker Compose: A VM to run multiple containers as a system
Watch this Docker vs Kubernetes video tutorial:
We have covered all the basics of Docker in this Docker cheat sheet. If you want to start learning DevOps in-depth, then check out the DevOps certification training offered by Intellipaat.
Not only will you get to learn and implement Docker with step-by-step guidance and support from us but you will also get to learn other important topics in DevOps such as Chef, Git/GitHub, Ansible, Jenkins, Puppet, Selenium, Nagios, and many more.
Here, at Intellipaat, you will also get 24/7 technical support from us that will help you with any of your queries in the respective technologies throughout the certification period. So, why wait? Check out the training program and enroll today!
Get in touch with Intellipaat for enrolling in its DevOps Training and be a certified DevOps Engineer!