Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconFull Stack Developmentbreadcumb forward arrow iconDocker Cheat Sheet to Quicken App Development

Docker Cheat Sheet to Quicken App Development

Last updated:
27th May, 2020
Views
Read Time
7 Mins
share image icon
In this article
Chevron in toc
View All
Docker Cheat Sheet to Quicken App Development

Working on Docker? You obviously can’t rely on your memory for the usual machine commands, and so, we present to you a comprehensive Docker cheat sheet.

Before working on Docker, it is important to become familiar with the associated terminology – Dockfires, images, etc. 

But first, let’s understand what Docker is and why it should be used.

Check out our free courses to get an edge over the competition

Ads of upGrad blog

What is Docker?

Also known as container manager, Docker is an open platform that helps developers develop and run applications.

But if Docker is a container manager, what is a container?

An environment in a capsule, running on shallow abstractions, meant for providing developers with virtual isolation to run processes without obstructions is called a container.

Docker is basically a place where you can manage these containers containing packaged software.

Check out upGrad’s Advanced Certification in Blockchain

Why use Docker?

Docker allows developers to build any kind of app in whichever language the client needs by using any toolchain that they prefer. Such apps are also portable and flexible to run anywhere, such as on Windows, Ubuntu, and Red Hat.

Since Docker tracks all the changes and manages them, it gets easier for the systems administrator to see how the app is being built and how it would work.

All in all, Docker is useful when you want to build high-quality apps faster.

Check out upGrad’s Advanced Certification in DevOps 

Learn more: Introduction to Docker Networking: Workflow, Networking

Explore Our Software Development Free Courses

Prerequisites for Working on Docker

1. Docker plugin along with zsh configuration manager to autocomplete Docker commands.

2. Linux – 3.10.x kernel or more

3. MacOS – 10.8 Mountain Lion or newer

Remember that after installing Docker, you need to check its version to know the features that are compatible with it. Here’s how you can find it out.

Use the command docker version to check the version of the Docker that you’re using.

Use the following command to know the server version.

$ docker version –format ‘{{.Server.Version}}’

Read: Docker Salary in India

Installing Docker

Here are links to install Docker on different operating systems.

Let’s now move on to container commands.

Explore our Popular Software Engineering Courses

Container Commands

What threads are to processes, containers are to virtual machines.

Here’s the chain of commands for different functions to perform on a container.

Lifecycle

In order to keep the container running, use docker run -td container_id.

Starting and stopping containers

  • docker start nginx – to start a container
  • docker stop nginx – to stop a container
  • docker restart nginx – to restart a container
  • docker pause nginx – to pause a container
  • docker unpause nginx – to unpause a container
  • docker wait nginx – to block a container
  • docker kill nginx – to send a SIGKILL
  • docker attach nginx – to attach to one container to an existing container

upGrad’s Exclusive Software Development Webinar for you –

SAAS Business – What is So Different?

 

Image Commands in Docker

  • Creating an image from a Dockerfile: Docker build [URL], and Docker build -t for building an image from a Dockerfile in the current directory and tags the image
  • Pulling an image from a registry: Docker pull [IMAGE]
  • Pushing an image to a registry: docker push [IMAGE]
  • Creating an image from a tarball: docker import [URL/FILE]
  • Creating an image from a container: Docker commit [CONTAINER] [NEW_IMAGE_NAME]
  • Removing an image: Docker rmi [IMAGE]
  • Loading an image from a tar archive or stdin: docker load [TAR_FILE/STDIN_FILE]
  • Saving an image to a tar archive, streamed to STDOUT with all parent layers, tags, and versions: Docker save [IMAGE] > [TAR_FILE]

In-Demand Software Development Skills

Container and Image Information Commands

To manage the containers after setting them up, it is important to get all the relevant information out of them. Use to following commands to get image and container details in Docker.

  • docker ps – to list all the running containers
  • docker ps -a – to list both stopped and running containers
  • docker logs [CONTAINER] – to get all logs from a running container
  • docker inspect [OBJECT_NAME/ID] – to list low-level information on Docker objects
  • docker events [CONTAINER] – to list all real-time events in a container
  • docker port [CONTAINER] – to show the specific mapping of a container
  • docker top [CONTAINER] – to display all running processes
  • docker stats [CONTAINER] – to display usage statistics of a container in real-time
  • docker diff [CONTAINER] – to display all changed to a file or directory in a container
  • docker image ls – to list all locally stored images in the Docker engine
  • docker history [IMAGE] – to see the history of an image

Check out : 12 Interesting Docker Project Ideas For Beginners

Loading and Saving Images Commands in Docker

  • docker load < my_image.tar.gz – to load an image from a file
  • docker save my_image:my_tag | gzip > my_image.tar.gz – to save an existing image

Importing and Exporting Container

  • cat my_container.tar.gz | docker import – my_image:my_tag – to import a container as an image
  • docker export my_container | gzip > my_container.tar.gz – to export an existing container

Learn Software Development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs or Masters Programs to fast-track your career.

Network Commands in Docker

1. To create a network, use the following command:

docker network create -d overlay MyOverlayNetworkdocker network create -d bridge MyBridgeNetworkdocker network create -d overlay \
  –subnet=192.167.0.0/16 \
  –subnet=192.172.0.0/16 \
  –gateway=192.167.0.100 \
  –gateway=192.172.0.100 \
  –ip-range=192.167.1.0/24 \
  –aux-address=”my-router=192.167.1.5″ –aux-address=”my-switch=192.167.1.6″ \
  –aux-address=”my-printer=192.172.1.5″ –aux-address=”my-nas=192.172.1.6″ \
  MyOverlayNetwork

2. To remove a network, use:

docker network rm MyOverlayNetwork

3. To list a network,

docker network ls

4. To get information about a network

docker network inspect MyOverlayNetwork

5. To connect a running container to a network

docker network connect MyOverlayNetwork nginx

6. To connect a container to a network when it starts

docker run -it -d –network=MyOverlayNetwork nginx

7. To disconnect a container from a network

docker network disconnect MyOverlayNetwork nginx

Also read: Docker Interview Questions & Answers

Ads of upGrad blog

Read our Popular Articles related to Software Development

Conclusion

This Docker cheat sheet should save you enough time while you’re working on building a high-quality app. Keep it handy at all times to quicken the process of app development! 

If you’re interested to learn more about docker, full stack software development , check out upGrad & IIIT-B’s PG Diploma in Full-stack Software Development which is designed for working professionals and offers 500+ hours of rigorous training, 9+ projects and assignments, IIIT-B Alumni status, practical hands-on capstone projects & job assistance with top firms.

Profile

Rohan Vats

Blog Author
Software Engineering Manager @ upGrad. Passionate about building large scale web apps with delightful experiences. In pursuit of transforming engineers into leaders.

Frequently Asked Questions (FAQs)

1Is Docker better than Virtual Machines (VM)?

Docker is an open platform container manager that enables developers and system coordinators to oversee the function of all the containers. It is accessible by any language and toolchain. Virtual Machines provide a software platform that developers use to go through an Operating System (OS). It utilizes an entire OS and has a singular non-shareable host kernel. Whereas in Docker, one OS can handle numerous workloads. Docker also allows one host kernel to be shared by multiple containers. In terms of storage space required, containers in Docker take up less space than Virtual Machines. Docker’s ability to operate from a single server gives it an upper hand over Virtual Machines. Hence, Docker is relatively better than Virtual Machines.

2How are Docker containers and images different?

Docker images and containers work with each other, which makes the functioning of Docker so optimal. They do vary in their origins and attributes. Docker images are the prototype or template through which Docker containers are reflected. Docker images are unchangeable; they provide a multi-layered structured template with guidelines for the container. This means that Docker containers cannot change by themselves unless their pre-existing Docker image is removed or updated. Since the image acts as a prototype, it’s made only once, while containers are producible for innumerable times. Docker images do not require containers to function, but containers are dependent on Docker images.

3Why are Kubernetes used with Docker?

Docker and Kubernetes collaborate to create scalable and functional application platforms. While Docker is excellent at intaking multiple containers and maintaining an Operating System, it does fall behind in running multiple containers independently and managing workloads significantly while scaling the containers across multiple servers. This is where Kubernetes can provide its expertise to ensure the smooth functioning of all the operations of Docker. It can handle vast containers and navigate their usage with specific users. So, while Docker focuses on containerization, Kubernetes provides orchestration of those containers.

Explore Free Courses

Suggested Blogs

Top 7 Node js Project Ideas &#038; Topics
31577
Node.JS is a part of the famous MEAN stack used for web development purposes. An open-sourced server environment, Node is written on JavaScript and he
Read More

by Rohan Vats

05 Mar 2024

How to Rename Column Name in SQL
46940
Introduction We are surrounded by Data. We used to store information on paper in enormous file organizers. But eventually, we have come to store it o
Read More

by Rohan Vats

04 Mar 2024

Android Developer Salary in India in 2024 [For Freshers &#038; Experienced]
901325
Wondering what is the range of Android Developer Salary in India? Software engineering is one of the most sought after courses in India. It is a reno
Read More

by Rohan Vats

04 Mar 2024

7 Top Django Projects on Github [For Beginners &amp; Experienced]
52112
One of the best ways to learn a skill is to use it, and what better way to do this than to work on projects? So in this article, we’re sharing t
Read More

by Rohan Vats

04 Mar 2024

Salesforce Developer Salary in India in 2024 [For Freshers &#038; Experienced]
909198
Wondering what is the range of salesforce salary in India? Businesses thrive because of customers. It does not matter whether the operations are B2B
Read More

by Rohan Vats

04 Mar 2024

15 Must-Know Spring MVC Interview Questions
34761
Spring has become one of the most used Java frameworks for the development of web-applications. All the new Java applications are by default using Spr
Read More

by Arjun Mathur

04 Mar 2024

Front End Developer Salary in India in 2023 [For Freshers &#038; Experienced]
902392
Wondering what is the range of front end developer salary in India? Do you know what front end developers do and the salary they earn? Do you know wh
Read More

by Rohan Vats

04 Mar 2024

Method Overloading in Java [With Examples]
26244
Java is a versatile language that follows the concepts of Object-Oriented Programming. Many features of object-oriented programming make the code modu
Read More

by Rohan Vats

27 Feb 2024

50 Most Asked Javascript Interview Questions &#038; Answers [2024]
4388
Javascript Interview Question and Answers In this article, we have compiled the most frequently asked JavaScript Interview Questions. These questions
Read More

by Kechit Goyal

26 Feb 2024

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon