CodeWiz Logo

    CodeWiz

    Docker Commands Cheat Sheet

    Docker Commands Cheat Sheet

    24/12/2024

    Introduction

    Docker is a powerful tool for developing, shipping, and running applications. This cheat sheet provides a comprehensive list of Docker commands to help you manage Docker images, containers, networks, volumes, and Docker Compose.

    Docker Images

    CommandDescription
    docker pull <image>Download an image from a registry
    docker imagesList all images on the local system
    docker rmi <image>Remove an image from the local system
    docker tag <image> <new_image>Tag an image with a new name
    docker build -t <image> <path>Build an image from a Dockerfile
    docker history <image>Show history of an image
    docker inspect <image>Display detailed information about an image
    docker push <image>Push an image to a registry

    Docker Containers

    CommandDescription
    docker run <image>Run a container from an image
    docker psList all running containers
    docker ps -aList all containers (running and stopped)
    docker stop <container>Stop a running container
    docker start <container>Start a stopped container
    docker restart <container>Restart a running container
    docker rm <container>Remove a stopped container
    docker exec -it <container> <command>Execute a command in a running container
    docker logs <container>View logs of a container
    docker inspect <container>Display detailed information about a container
    docker container pruneRemove all stopped containers

    Docker Networks

    CommandDescription
    docker network lsList all networks
    docker network create <network>Create a new network
    docker network rm <network>Remove a network
    docker network connect <network> <container>Connect a container to a network
    docker network disconnect <network> <container>Disconnect a container from a network

    Docker Volumes

    CommandDescription
    docker volume lsList all volumes
    docker volume create <volume>Create a new volume
    docker volume rm <volume>Remove a volume
    docker volume inspect <volume>Display detailed information about a volume

    Docker Compose

    CommandDescription
    docker-compose upCreate and start containers
    docker-compose downStop and remove containers, networks, images, and volumes
    docker-compose buildBuild or rebuild services
    docker-compose logsView output from containers
    docker-compose psList containers
    docker-compose exec <service> <command>Execute a command in a running service container
    docker-compose stopStop running containers without removing them
    docker-compose startStart existing containers for a service

    Conclusion

    This Docker commands cheat sheet provides a quick reference to the most commonly used Docker commands. Whether you're managing images, containers, networks, volumes, or using Docker Compose, this guide will help you navigate Docker with ease.

    To stay updated with the latest tutorials, follow us on YouTube, LinkedIn, and Medium.

    Video Version

    To watch a more detailed video version of this cheat sheet, see the video below: