To Data & Beyond

To Data & Beyond

Share this post

To Data & Beyond
To Data & Beyond
10 Docker Commands for 90% of Conteraization Tasks

10 Docker Commands for 90% of Conteraization Tasks

10 Essential Docker Commands You Should Know

Youssef Hosni's avatar
Youssef Hosni
Mar 06, 2025
∙ Paid
24

Share this post

To Data & Beyond
To Data & Beyond
10 Docker Commands for 90% of Conteraization Tasks
1
Share

Get 50% off for 1 year

Docker has revolutionized the world of software development and deployment by introducing containerization, a lightweight and efficient method of packaging applications and their dependencies.

With Docker, developers can create isolated environments known as containers that can run consistently across different platforms, making it easier to build, deploy, and scale applications. However, to truly leverage the power of Docker, it is essential to master the fundamental commands that enable effective container management.

In this article, we will explore ten essential Docker commands that every developer and system administrator should know to streamline their container management process. From creating and starting containers to listing available images and gracefully stopping them, these commands will serve as building blocks for managing your Docker environment efficiently.

By mastering these commands, you will gain a solid foundation for managing Docker containers efficiently and effectively. Whether you are a beginner getting started with Docker or an experienced user looking to enhance your container management skills, this article will provide valuable insights and practical examples to help you navigate the world of Docker with confidence. Let’s dive in and unlock the full potential of Docker’s containerization capabilities.

10 Essential Docker Commands You Should Know / Image by Author

Table of Contents:

  • docker run: Create and start a new container based on an image.

  • docker ps: Display running containers on the Docker host.

  • docker stop: Gracefully stop a running container.

  • docker rm: Remove stopped containers.

  • docker images: List available Docker images.

  • docker rmi: Remove Docker images.

  • docker build: Build a Docker image from a Dockerfile.

  • docker exec: Execute a command inside a running container.

  • docker pull: Download Docker images.

  • docker push: Upload Docker images to a registry.


My New Course: Technical Writing As A Side Hustle

Youssef Hosni
·
Feb 6
My New Course: Technical Writing As A Side Hustle

I am happy to announce that I have released my new course: 𝐓𝐞𝐜𝐡𝐧𝐢𝐜𝐚𝐥 𝐖𝐫𝐢𝐭𝐢𝐧𝐠 𝐚𝐬 𝐚 𝐒𝐢𝐝𝐞 𝐇𝐮𝐬𝐭𝐥𝐞: Comprehensive Guide to Earn Part-Time Job Earnings from Technical Writing.

Read full story

1. docker run

The “docker run” command is used to create and start a new container based on a Docker image. Here’s the basic syntax for running a container:

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
  • OPTIONS: Additional options that can be used to customize the container’s behavior, such as specifying ports, volumes, environment variables, etc.

  • IMAGE: The name of the Docker image to use for creating the container.

  • COMMAND: (Optional) The command to be executed inside the container.

  • ARG: (Optional) Arguments passed to the command inside the container.

For example, to run a container based on the “ubuntu” image and execute the “ls” command inside the container, you would use the following command:

docker run ubuntu ls

This will create a new container using the “ubuntu” image and run the “ls” command, which lists the files and directories inside the container’s file system.

Note that if the specified image is not available locally, Docker will automatically pull it from a Docker registry before creating the container.

2. docker ps

The “docker ps” command is used to list the running containers on your Docker host. It provides information such as the container ID, the image used, the command being executed, status, and port mappings. Here’s the basic syntax:

docker ps [OPTIONS]

By default, “docker ps” only shows the running containers. If you want to see all containers, including those that are stopped or exited, you can use the “-a” option:

docker ps -a

This will display a list of all containers on your Docker host, along with their respective details.

The output of the “docker ps” command includes columns like CONTAINER ID, IMAGE, COMMAND, CREATED, STATUS, PORTS, and NAMES. Here’s a brief explanation of these columns:

  • CONTAINER ID: The unique identifier for the container.

  • IMAGE: The name or ID of the image used to create the container.

  • COMMAND: The command executed inside the container.

  • CREATED: The timestamp indicates when the container was created.

  • STATUS: The current state of the container (e.g., running, stopped, exited).

  • PORTS: The port mappings between the container and the host system.

  • NAMES: The automatically generated or user-assigned name of the container.

By default, the “docker ps” command provides a summarized view of the containers. If you want more detailed information, you can add the “ — format” option followed by a format template. For example:

docker ps --format "ID: {{.ID}}, Image: {{.Image}}, Status: {{.Status}}"

This will display only the container ID, image, and status information for each container. Please note that running the “docker ps” command requires Docker to be installed and running on your system.

3. docker stop

The “docker stop” command is used to stop one or more running containers. It sends a signal to the container’s main process, requesting it to stop gracefully. Here’s the basic syntax:

docker stop [OPTIONS] CONTAINER [CONTAINER...]
  • OPTIONS: Additional options that can be used to customize the stop behavior. For example, you can specify a timeout period with the “ — time” or “-t” option to allow the container more time to stop gracefully before forcefully terminating it.

  • CONTAINER: The name or ID of the container(s) to stop. You can specify multiple containers separated by spaces.

For example, to stop a container with the name “my-container”, you would use the following command:

docker stop my-container

If you want to stop multiple containers, you can list their names or IDs separated by spaces:

docker stop container1 container2 container3

When the “docker stop” command is executed, Docker sends a SIGTERM signal to the container, allowing the process inside to perform any necessary cleanup tasks and shut down gracefully. If the process doesn’t stop within the given timeout period (default is 10 seconds), Docker can send a SIGKILL signal to force the termination of the container.

4. docker rm

The “docker rm” command is used to remove one or more stopped containers from your Docker host. It permanently deletes the specified container(s) and frees up the associated resources. Here’s the basic syntax:

docker rm [OPTIONS] CONTAINER [CONTAINER...]
  • OPTIONS: Additional options that can be used to customize the removal behavior. For example, you can use the “-f” or “ — force” option to force the removal of a running container.

  • CONTAINER: The name or ID of the container(s) to remove. You can specify multiple containers separated by spaces.

For example, to remove a container with the name “my-container”, you would use the following command:

docker rm my-container

If you want to remove multiple containers, you can list their names or IDs separated by spaces:

docker rm container1 container2 container3

By default, the “docker rm” command only removes stopped containers. If you want to remove running containers as well, you can use the “-f” or “ — force” option:

docker rm -f container1 container2

Please note that removing a container will permanently delete it, including any data or changes made within the container. If you want to remove a running container, it will be stopped first before being removed.

Additionally, you can use the “-v” or “ — volumes” option with the “docker rm” command to remove the associated volumes along with the container, if any.

5. docker images

The “docker images” command is used to list the Docker images that are available on your Docker host. It displays information about the images, such as the repository, tag, image ID, creation date, and size. Here’s the basic syntax:

docker images [OPTIONS] [REPOSITORY[:TAG]]
  • OPTIONS: Additional options that can be used to customize the output or filter the images. For example, you can use the “ — format” option to specify a format template for the output or the “-a” or “ — all” option to show all images, including intermediate image layers.

  • REPOSITORY: (Optional) The repository name of the image.

  • TAG: (Optional) The tag of the image.

By default, the “docker images” command lists all images available on your Docker host. For example:

docker images

This will display a table of images, including columns like REPOSITORY, TAG, IMAGE ID, CREATED, and SIZE. The REPOSITORY and TAG together form the unique identifier for an image.

If you want to filter the images based on the repository or tag, you can provide the repository and/or tag name as arguments. For example, to list images from a specific repository:

docker images my-repo

To list images with a specific tag:

docker images my-repo:my-tag

You can also combine options to further customize the output. For example, to show all images, including intermediate layers, and use a custom format for the output:

docker images -a --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"

This will display the images in a table format, showing only the image ID, repository, and tag information.

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2025 Youssef Hosni
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share