Docker Cheat Sheet: All the Most Essential Docker Commands That Every Developer Should Know in 2024

4 min read
Last updated: Dec 1, 2024

what-is-docker

Docker is a tool designed to make it easier for developers to create, deploy, and run applications by using containers. Containers allows a developer to deploy an application as one package, which consists of all the required libraries, system tools, code and dependencies. Now, the developer can rest assured that the application will run on any other machine. The applications execution environment share operating system kernel but otherwise run in isolation from one another.

docker-2

Consider containers as an extremely lightweight and modular virtual machines. You can easily create, deploy, copy, delete, and move these containers from environment to environment. They isolate applications execution environments from one another, but share the underlying OS kernel.

The Docker technology uses the Linux kernel and it’s features like Cgroups, which govern the isolation and usage of system resources, such as CPU and memory, for a group of processes and namespaces, which wrap a set of system resources and present them to a process to make it look like they are dedicated to that process; to segregate processes so they can run independently. This independence is the intention of containers—the ability to run multiple processes and apps separately from one another to make better use of your infrastructure while retaining the security you would have with separate systems.

Most business applications consist of several separate components: a web server, a database, an in-memory cache. Containers make it possible to compose these pieces into an individual functional unit. Each piece can be maintained, updated, swapped out, and modified independently of the others. This is essentially the microservices model of application design. By dividing application functionality into separate, self-contained services. Lightweight and portable containers make it easier to build and maintain microservices-based applications.

Download

https://www.docker.com/products/docker-desktop

Most Essential Docker Commands That Every Developer Should Know

  • docker run: This command is used to create and start a new container based on a specified image.

    Example: docker run hello-world

    This command pulls the “hello-world” image from the Docker registry and starts a container based on it.

  • docker build: This command is used to build a new Docker image based on a Dockerfile.

    Example: docker build -t myapp .

    This command builds a Docker image with the tag “myapp” using the Dockerfile in the current directory.

  • docker images: This command lists all the Docker images available on your local machine.

    Example: docker images

    This command displays a list of all the Docker images along with their repository, tag, and size.

  • docker ps: This command lists all the running containers.

    Example: docker ps

    This command shows a list of all the currently running containers along with their container ID, image used, status, and other details.

  • docker stop: This command is used to stop a running container.

    Example: docker stop mycontainer

    This command stops the container with the name or ID “mycontainer”.

  • docker rm: This command removes a container.

    Example: docker rm mycontainer

    This command removes the container with the name or ID “mycontainer”.

  • docker pull: This command is used to download Docker images from a Docker registry.

    Example: docker pull ubuntu:latest

    This command pulls the latest version of the Ubuntu image from the Docker registry.

  • docker push: This command is used to push a Docker image to a Docker registry.

    Example: docker push myusername/myimage

    This command pushes the image with the tag “myusername/myimage” to a Docker registry, making it available for others to use.

  • docker exec: This command is used to execute a command inside a running container.

    Example: docker exec -it mycontainer sh

    This command opens an interactive shell session inside the container with the name or ID “mycontainer”.

  • docker-compose: Docker Compose is a tool for defining and running multi-container Docker applications using a YAML file.

    Example: docker-compose up

    This command starts the containers defined in the docker-compose.yml file in the current directory.

Ending Note

You can use Docker containers as a core building block creating modern applications and platforms. Docker makes it easy to build and run distributed microservices architectures, deploy your code with standardized continuous integration and delivery pipelines, build highly-scalable data processing systems, and create fully-managed platforms for your developers.

Docker simplifies and accelerates your workflow, while giving developers the freedom to innovate with their choice of tools, application stacks, and deployment environments for each project.

Refer well written docker documentation https://docs.docker.com/get-started/.

Refer Sample dockerfiles: https://github.com/sanmak/dockerfile-samples.

Any thoughts, let's discuss on twitter

Sharing this article is a great way to educate others like you just did.



If you’ve enjoyed this issue, do consider subscribing to my newsletter.


Subscribe to get more such interesting content !

Tech, Product, Money, Books, Life. Discover stuff, be inspired, and get ahead. Box Piper is on Twitter and Discord. Let's Connect!!

To read more such interesting topics, let's go Home

More Products from the maker of Box Piper:

Follow GitPiper Instagram account. GitPiper is the worlds biggest repository of programming and technology resources. There is nothing you can't find on GitPiper.

Follow SharkTankSeason.com. Dive into the riveting world of Shark Tank Seasons. Explore episodes, pitches, products, investment details, companies, seasons and stories of entrepreneurs seeking investment deals from sharks. Get inspired today!.


Scraper API

More Blogs from the house of Box Piper: