Docker Cheatsheet

·

2 min read

Docker Cheatsheet

Docker Concepts:

  1. Images: Read-only templates used to create Docker containers.

  2. Containers: Running instances of Docker images.

  3. Dockerfile: A text file that contains instructions to build a Docker image.

  4. Docker Registry: A centralized repository for storing and sharing Docker images (e.g., Docker Hub).

Commands for Installing Docker

Installing docker on Ubuntu machine-

sudo apt install docker.io

Basic Docker Commands

Image Management:

  • docker images: List all available Docker images.

  • docker pull <image_name>: Download an image from a registry.

  • docker build -t <image_name> <path_to_dockerfile>: Build an image using a Dockerfile.

  • docker rmi <image_name>: Remove an image.

  1. Container Management:

    • docker run <image_name>: Create and start a new container from an image.

    • docker ps: List running containers.

    • docker ps -a: List all containers (including stopped ones).

    • docker start <container_id>: Start a stopped container.

    • docker stop <container_id>: Stop a running container.

    • docker rm <container_id>: Remove a container.

  2. Interacting with Containers:

    • docker exec -it <container_id> <command>: Run a command inside a running container.

    • docker cp <container_id>:<container_path> <host_path>: Copy files between a container and the host.

  3. Networking:

    • docker network ls: List Docker networks.

    • docker network create <network_name>: Create a new Docker network.

    • docker network connect <network_name> <container_id>: Connect a container to a network.

  4. Volumes:

    • docker volume ls: List Docker volumes.

    • docker volume create <volume_name>: Create a new Docker volume.

    • docker run -v <volume_name>:<container_path> <image_name>: Mount a volume in a container.

  5. Docker Compose:

    • docker-compose up: Create and start containers defined in a Compose file.

    • docker-compose down: Stop and remove containers defined in a Compose file.

  6. Miscellaneous:

    • docker logs <container_id>: View the logs of a container.

    • docker inspect <container_id>: Get detailed information about a container.

Thanks for Reading!