Docker Cheat Sheet for getting started easily

Reading Time: 3 minutes

Docker is free software developed by Docker Inc. The time after its release it became a must in the field of IT development. It allows users to create independent and isolated environments.
It is very helpful in launching and deploying any applications easily. These deployed applications are available to us in form containers.

Containers give isolated environments from one another and bundle their own software, libraries, and configuration files. They can communicate with each other through well-defined channels. They use fewer resources than virtual machines because they share the services of a single Operating System. Hence, docker enables developers to easily pack, ship, and run any application as a lightweight, portable, self-sufficient container, which can run virtually anywhere.

Let’s get started with some very often used commands.

Docker Registries and Repositories

The Registry is a stateless, highly scalable server-side application that stores and lets you distribute Docker images. The Registry is open-source, under the permissive Apache license. A registry is a storage and content delivery system, holding named images, available in different tagged versions.

Login to Registry

docker login [OPTIONS] [SERVER]

// login to self-hosted repository 

docker login localhost:8080

Logout from Registry

docker logout [SERVER]

docker logout localhost:8080

Pulling an Image

docker pull [OPTIONS] NAME[:TAG|@DIGEST]

docker pull fedora

docker pull knoldusregistory.localhost:5000/myadmin/testimage

Pushing an Image

docker push knoldusrepository/nginx

docker push knoldusrepository/nginx localhost:5000/myadmin/nginx

Searching an Image

docker search [OPTIONS] TERM

docker search nginx

docker search --filter=stars=3 --no-trunc busybox

Play with Containers in Docker

Creating a Container

docker create [OPTIONS] IMAGE [COMMAND] [ARG...]

docker create -t -i knoldusregistry/coolcontainers --name coolcontainers

Running a Container

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

docker run -it --name coolcontainers -d knoldusregistry/coolcontainers

Renaming a Container

docker rename CONTAINER NEW_NAME

docker rename coolcontainers awesomecontainers

Updating a Container


docker update --cpu-shares 512 -m 300M coolcontainers

Removing a Container


docker rm --force fedora

Starting a Container


docker start nginx

Stopping a Container


docker stop nginx

Restarting a Container

docker restart nginx

Pausing a Container

docker pause nginx

Unpausing a Container

docker unpause nginx

Blocking a Container

docker wait nginx

Sending a SIGKILL

docker kill nginx

Connecting to an existing Container

docker attach [OPTIONS] CONTAINER

docker attach nginx

Getting information about Containers

Getting Information About the Containers in Docker

Running Containers

docker ps

docker ps -a

Containers Logs

docker logs coolcontainers

Inspecting containers

docker inspect coolcontainers

docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q)

Containers Events

docker events coolcontainers

Public Ports

docker port coolcontainers

Running Processes

docker top coolcontainers

Container Resource Usage

docker stats coolcontainers

Playing with Images in Docker

Listing Images

docker images

Building Images

docker build [OPTIONS] PATH | URL | -

docker build .

docker build

docker build - < Dockerfile

docker build - < context.tar.gz

docker build -t knoldusregistry/coolcontainer .

docker build -f myDockerfile .

curl | docker build -f - .

Removing an Image

docker rmi nginx

Showing History of an Image

docker history

Creating an Image from a Container

docker commit nginx

Tagging an Image

docker tag nginx knoldusregistry/nginx

Pushing an Image

docker push knoldusregistry/nginx

You can download the cheat sheet from here. For more such blogs keep following knoldus blogs. If you liked this post, please recommend it and share it with your followers.Have fun! Happy learning!

Written by 

Saumya is a Software Consultant at Knoldus Software LLP. She has done B.Tech from Quantum School of Technology, Roorkee. She has good knowledge of Devops technologies like Ansible, Terraform, Docker, Concourse, Jenkins, Kubernetes. She is very enthusiastic and energetic. Apart from technology, she is interested in various sports.