In this article, I want to share all the docker commands required in our day-to-day life. the command is very easy and useful for quick results. So, I am sharing it in the form of a docker cheatsheet.
What is docker?
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers.
Why docker?
Docker is useful for automating the deployment of applications inside software containers, which makes the applications easy to ship and run virtually anywhere (i.e., platform-independent). The Docker container processes run on the host kernel, unlike VM which runs processes in the guest kernel.
Docker Installation
The docker desktop downloads are available for Windows, Mac and Linux distributions.
Windows
It supports Windows 10 64-bit: Home, Pro, Enterprise, or Education, version 1903 (Build 18362 or higher). You need to follow the below steps for installation.
- Download the docker desktop for Windows from https://docs.docker.com/docker-for-windows/install/
- Double-click Docker Desktop Installer.exe to run the installer.
- Make sure the Enable Hyper-V Windows Features option is selected
Mac
- Download the docker desktop for Mac from https://docs.docker.com/docker-for-mac/install/
- Double-click Docker.dmg to open the installer and drag it to the Applications folder.
- Double-click Docker.app in the Applications folder to start Docker.
Linux
You can install from a package easily
- Go to https://download.docker.com/linux/ubuntu/dists/, choose your Ubuntu version and then go to pool/stable/ to get the .deb file
- Install Docker Engine by referring to the downloaded location of the Docker package.
$ sudo dpkg -i /path/to/package.deb
- Verify the Docker Engine by running the hello-world image to check the correct installation.
$ sudo docker run hello-world
Registries and Repositories
Registry
Docker Registry is a service that stores your docker images. It could be hosted by a third party, as public or private registry. Some of the examples are,
- Docker Hub,
- Quay,
- Google Container Registry,
- AWS Container Registry
Repository
A Docker Repository is a collection of related images with the same name which have different tags. These tags are alphanumeric identifiers(like 1.0 or the latest) attached to images within a repository.
For example, if you want to pull a Golang image using docker pull golang:latest
command, it will download the image tagged latest within the golang
repository from the Docker Hub registry. The tags appeared on the docker hub as below,
Login
Login to a registry
> docker login [OPTIONS] [SERVER]
[OPTIONS]:
-u/--username username
-p/--password password
Example:
1. docker login localhost:8080 // Login to a registry on your localhost
2. docker login
Logout
Logout from a registry
> docker logout [SERVER]
Example:
docker logout localhost:8080 // Logout from a registry on your localhost
Search image
Search for an image in registry
docker search [OPTIONS] TERM
Example:
docker search golang
docker search --filter stars=3 --no-trunc golang
Pull image
This command pulls an image or a repository from a registry to the local machine
docker image pull [OPTIONS] NAME[:TAG|@DIGEST]
Example:
docker image pull golang:latest
Push image
This command pushes an image to the registry from the local machine.
docker image push [OPTIONS] NAME[:TAG]
docker image push golang:latest
These are some basic docker commands. for more commands and a complete cheatsheet, check my Blog at TechAlgoSpotlight
Support
If you like these articles and are looking for more articles like this, check out my Website.
Thank you