Skip to main content

Command Palette

Search for a command to run...

Docker Commands Cheatsheet

Updated
2 min read
Docker Commands Cheatsheet
R

Devrel manager cerbos.dev

Docker Commands Cheat Sheet

Container Lifecycle

  • Creating and Starting a Container

    • docker run -d --name my_container nginx- Use this command to create and start a container named my_container using the nginx image.
  • Starting, Stopping, and Restarting Containers

    • docker stop my_container - Stops the specified container.

    • docker start my_container - Starts a previously stopped container.

    • docker restart my_container - Restarts a container.

  • Listing Containers

    • docker ps - Lists all currently running containers.

    • docker ps -a - Lists all containers, including those that are stopped.

Image Management

  • Fetching an Image from a Registry

    • docker pull ubuntu- Retrieves the ubuntu image from the Docker Hub or other specified registry.
  • Building an Image from a Dockerfile

    • docker build -t my_image .- Builds an image named my_image from a Dockerfile in the current directory.
  • Listing and Removing Images

    • docker images - Lists all local Docker images.

    • docker rmi my_image - Removes the specified image from the local system.

Container Operations

  • Interacting with Containers

    • docker exec -it my_container bash - Executes a command (bash in this case) inside a running container.

    • docker attach my_container - Attaches to a running container for interaction.

    • docker logs my_container - Displays logs from the specified container.

  • Managing Container Resources

    • docker cp file.txt my_container:/path/to/destination - Copies files between a container and the host system.

    • docker pause my_container and docker unpause my_container - Pauses or unpauses a running container.

    • docker inspect my_container - Displays detailed information about a specific container.

Networking

  • Network Management

    • docker network ls - Lists all networks available on the Docker host.

    • docker network create my_network - Creates a new network.

    • docker network connect my_network my_container and docker network disconnect my_network my_container - Connects or disconnects a container from a network.

Volume Management

  • Volume Commands

    • docker volume ls - Lists all Docker volumes.

    • docker volume create my_volume - Creates a new volume named my_volume.

    • docker volume rm my_volume - Removes the specified volume.

    • docker volume inspect my_volume - Provides detailed information about a specific volume.

Follow Rohit Ghumare for more such an amazing content.

Check DevOpscommunity.in for more FREE resources.