Cloud Computing

The Ultimate List of Docker Commands for Developers

Docker is an amazing tool that makes it easy to build, ship, and run applications in containers. Whether you’re just getting started or need a quick refresher, this guide covers all the essential Docker commands. Let’s dive in!

1. Managing Containers

Think of containers as lightweight virtual machines running your applications.

  • See running containers
    • docker ps or docker container ps
  • See all containers (including stopped ones)
    • docker ps -a or docker container ps -a
  • Start a container
    • docker start <container_id> or docker container start <container_id>
  • Stop a container
    • docker stop <container_id> or docker container stop <container_id>
  • Restart a container
    • docker restart <container_id> or docker container restart <container_id>
  • Remove a container
    • docker rm <container_id> or docker container rm <container_id>
  • Force remove a container
    • docker rm -f <container_id> or docker container rm -f <container_id>
  • Run a new container
    • docker run --name <container_name> <image_name> or docker container run --name <container_name> <image_name>
  • Run a container in the background
    • docker run -d <image_name> or docker container run -d <image_name>
  • Run a container with interactive shell
    • docker run -it <image_name> /bin/bash or docker container run -it <image_name> /bin/bash
  • Run a container and delete it after exit
    • docker run --rm <image_name> or docker container run --rm <image_name>
  • Executes a command inside a running container.
    • docker exec -it <container_id> <command> or docker container exec -it <container_id> <command>

2. Working with Images

Docker images are like blueprints for your containers.

Here’s how to manage Images:

  • List all images
    • docker images
  • Remove an image
    • docker rmi <image_id>
  • Force remove an image
    • docker rmi -f <image_id>
  • Download an image from Docker Hub
    • docker pull <image_name>
  • Build an image from a Dockerfile
    • docker build -t <image_name> .
  • Tag an image
    • docker tag <image_id> <new_image_name>
  • Upload an image to Docker Hub
    • docker push <image_name>

3. Managing Networks

Need your containers to talk to each other? Docker networks make it easy:

  • See available networks
    • docker network ls
  • Create a new network
    • docker network create <network_name>
  • Remove a network
    • docker network rm <network_name>
  • Inspect a network’s details
    • docker network inspect <network_name>
  • Connect a container to a network
    • docker network connect <network_name> <container_id>
  • Disconnect a container from a network
    • docker network disconnect <network_name> <container_id>

4. Handling Volumes (Persistent Storage)

If you need to store data even after a container stops, Docker volumes are the way to go:

  • List all volumes
    • docker volume ls
  • Create a volume
    • docker volume create <volume_name>
  • Remove a volume
    • docker volume rm <volume_name>
  • Inspect a volume
    • docker volume inspect <volume_name>

5. Checking Logs & Monitoring

Want to debug or see what’s happening inside a container? These commands help:

  • View container logs
    • docker logs <container_id>
  • View last 10 lines of logs
    • docker logs --tail 10 <container_id>
  • Follow logs in real-time
    • docker logs -f <container_id>
  • Check container resource usage
    • docker stats
  • See processes running inside a container
    • docker top <container_id>

6. Running Commands Inside Containers

Need to interact with a running container? Try these:

  • Open a shell inside a running container
    • docker exec -it <container_id> /bin/bash
  • Attach to a running container’s console
    • docker attach <container_id>

7. Docker Compose (Managing Multi-Container Apps)

For projects with multiple containers, Docker Compose is your best friend:

  • Start services in the background
    • docker-compose up -d
  • Stop all services
    • docker-compose down
  • Restart services
    • docker-compose restart
  • View logs for all services
    • docker-compose logs

8. Cleaning Up Docker Resources

Docker can accumulate a lot of unused stuff over time. Here’s how to keep things clean:

  • Remove unused images
    • docker image prune
  • Remove all stopped containers
    • docker container prune
  • Remove all unused networks
    • docker network prune
  • Remove all unused volumes
    • docker volume prune
  • Clean up everything (images, containers, networks, and volumes)
    • docker system prune -a

9. Docker Management Commands

Docker management commands are used to manage and interact with the Docker system. Here are some key Docker management commands:

  • Shows the version of Docker installed
    • docker version
  • Displays system-wide information about Docker
    • docker info
  • Displays help information for Docker commands
    • docker --help

10. Docker Swarm Commands

Docker Swarm is used for container orchestration in production environments. Here are some key Docker swarm commands:

  • Initializes a swarm
    • docker swarm init
  • Join a swarm as a node and/or manager
    • docker swarm join <options> HOST:PORT
  • Display and rotate the root CA
    • docker swarm ca
  • Manage join tokens
    • docker swarm join-token <worker|manager>
  • Leave the swarm
    • docker swarm leave
  • Unlock swarm
    • docker swarm unlock
  • Manage the unlock key
    • docker swarm unlock-key
  • Update the swarm
    • docker swarm update <options>

Conclusion

Docker is a game-changer for developers, making it super easy to package, deploy, and manage applications. Whether you’re running a simple web app or a complex microservices architecture, mastering these commands will make your life a whole lot easier.

Thanks for reading!

Subscribe to our newsletter

Get practical tech insights, cloud & AI tutorials, and real-world engineering tips — delivered straight to your inbox.

No spam. Just useful content for builders.

Leave a Reply

Your email address will not be published. Required fields are marked *