Ultimate Docker CheatSheet in 2024

Krunal Kanojiya - Jul 9 - - Dev Community

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.

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

$ sudo dpkg -i /path/to/package.deb
Enter fullscreen mode Exit fullscreen mode
  • Verify the Docker Engine by running the hello-world image to check the correct installation.
$ sudo docker run hello-world
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Logout

Logout from a registry

> docker logout [SERVER]

Example:

docker logout localhost:8080 // Logout from a registry on your localhost
Enter fullscreen mode Exit fullscreen mode

Search image

Search for an image in registry

docker search [OPTIONS] TERM

Example:
docker search golang
docker search --filter stars=3 --no-trunc golang
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

TechAlgoSpotlight

Thank you

. . . . . . . . . . . . . . . . . . . . .
Terabox Video Player