Essential Docker Commands You Must Know

Docker has revolutionized containerization, making it easier for developers and system administrators to build, deploy, and manage applications. Knowing the fundamental commands is crucial for efficiency, whether you’re new to Docker or an experienced user. This blog post covers the essential Docker commands that every developer should know.

1. Basic Docker Commands

Before diving into container management, let’s start with some basic Docker commands:

  • Check Docker Version docker --version
    • This confirms that Docker is installed and running.
  • View System Information docker info
    • Displays system-wide information about Docker.

2. Container Management Commands

Containers are the core of Docker. Here are essential commands to manage them:

  • List Running Containers docker ps
  • List All Containers (Including Stopped) docker ps -a
  • Run a Container docker run -d --name my_container nginx
  • Run a Container with an Interactive Shell docker run -it ubuntu bash
  • Stop a Running Container docker stop <container_id>
  • Start a Stopped Container docker start <container_id>
  • Restart a Container docker restart <container_id>
  • Remove a Container docker rm <container_id>
  • Remove All Stopped Containers docker container prune

3. Image Management

Docker images serve as templates for containers. These commands help in managing images:

  • List Docker Images docker images
  • Pull an Image from Docker Hub docker pull nginx
  • Remove an Image docker rmi <image_id>
  • Remove All Unused Images docker image prune -a

4. Networking in Docker

Networking is a crucial part of Docker’s functionality. Here’s how to manage it:

  • List Docker Networks docker network ls
  • Create a Network docker network create my_network
  • Connect a Container to a Network docker network connect my_network my_container
  • Disconnect a Container from a Network docker network disconnect my_network my_container

5. Managing Storage with Volumes

Volumes allow data persistence in Docker. Use these commands to manage them:

  • List Docker Volumes docker volume ls
  • Create a Volume docker volume create my_volume
  • Remove a Volume docker volume rm my_volume
  • Run a Container with a Volume docker run -d -v my_volume:/data nginx

6. Debugging and Logs

When things go wrong, these commands help debug and inspect containers:

  • View Logs of a Container docker logs <container_id>
  • Follow Logs in Real-time docker logs -f <container_id>
  • View Running Processes in a Container docker top <container_id>
  • Inspect a Container’s Details docker inspect <container_id>

7. Executing Commands Inside a Container

Sometimes, you need to access a running container’s shell:

  • Execute a Command Inside a Running Container docker exec -it <container_id> bash
  • Attach to a Running Container’s Terminal docker attach <container_id>

8. Docker Compose Commands

Docker Compose simplifies multi-container applications:

  • Start Services in Docker Compose docker-compose up -d
  • Stop and Remove Containers from Compose docker-compose down

In Summary

As you know, I do all my development, testing, demos, and other things for GoldenGate in Docker. Mastering these Docker commands will help you work efficiently with containers, networks, and images. Whether managing a single container or orchestrating multi-container applications, these commands form the foundation of containerized application development. Start practicing today and make Docker a crucial part of your DevOps workflow!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.