Day 20: Docker CheatSheet

Radheya Zunjur
3 min readJul 6, 2023

--

Throughout the Docker series, we have explored the in’s and out’s of Docker, from the basics to advanced topics. We have covered containerization, image management, container orchestration, networking, storage, security, and optimization.

In this concluding article, we will bring together all the knowledge we have gained so far and provide you with a holistic understanding of Docker’s capabilities. Here is the final cheatsheet for you all -

Docker Commands:

1. docker run: Create and run a new container based on an image.

Example: docker run <image>

2. docker ps: List running containers.

Example: docker ps

3. docker images: List available images.

Example: docker images

4. docker pull: Download an image from a registry.

Example: docker pull <image>

5. docker build: Build an image from a Dockerfile.

Example: docker build -t <image_name> <path_to_dockerfile>

6. docker start: Start a stopped container.

Example: docker start <container>

7. docker stop: Stop a running container.

Example: docker stop <container>

8. docker restart: Restart a running container.

Example: docker restart <container>

9. docker rm: Remove a stopped container.

Example: docker rm <container>

10. docker rmi: Remove an image.

Example: docker rmi <image>

11. docker exec: Run a command inside a running container.

Example: docker exec <container> <command>

12. docker cp: Copy files/folders between a container and the local filesystem.

Example: docker cp <container>:<path_to_file> <local_path>

13. docker logs: Fetch the logs of a container.

Example: docker logs <container>

14. docker inspect: View detailed information about a container or image.

Example: docker inspect <container/image>

15. docker network ls: List Docker networks.

Example: docker network ls

16. docker network create: Create a Docker network.

Example: docker network create <network_name>

17. docker network connect: Connect a container to a network.

Example: docker network connect <network> <container>

18. docker network disconnect: Disconnect a container from a network.

Example: docker network disconnect <network> <container>

Docker-Compose Commands:

1. docker-compose up: Create and start containers defined in the docker-compose.yml file.

Example: docker-compose up

2. docker-compose down: Stop and remove containers, networks, and volumes defined in the docker-compose.yml file.

Example: docker-compose down

3. docker-compose build: Build or rebuild services defined in the docker-compose.yml file.

Example: docker-compose build

4. docker-compose start: Start services defined in the docker-compose.yml file.

Example: docker-compose start

5. docker-compose stop: Stop services defined in the docker-compose.yml file.

Example: docker-compose stop

6. docker-compose restart: Restart services defined in the docker-compose.yml file.

Example: docker-compose restart

7. docker-compose ps: List containers of services defined in the docker-compose.yml file.

Example: docker-compose ps

8. docker-compose logs: Fetch the logs of services defined in the docker-compose.yml file.

Example: docker-compose logs

9. docker-compose exec: Run a command inside a running service container.

Example: docker-compose exec <service> <command>

10. docker-compose pull: Download updated images for services defined in the docker-compose.yml file.

Example: docker-compose pull

11. docker-compose rm: Remove stopped containers for services defined in the docker-compose.yml file.

Example: docker-compose rm

12. docker-compose config: Validate and view the composed configuration.

Example: docker-compose config

13. docker-compose scale: Scale services up or down.

Example: docker-compose scale <service>=<num_instances>

14. docker-compose run: Run a one-time command against a service container.

Example: docker-compose run <service> <command>

15. docker-compose pause: Pause services.

Example: docker-compose pause <service>

16. docker-compose unpause: Unpause services.

Example: docker-compose unpause <service>

17. docker-compose up -d: Create and start containers in detached mode.

Example: docker-compose up -d

18. docker-compose down -v: Stop and remove containers, networks, volumes, and images defined in the docker-compose.yml file.

Example: docker-compose down -v

As we conclude our Docker series, we hope that you have gained a comprehensive understanding of Docker and its vast capabilities. By now, you should feel confident in creating, managing, and optimizing containers, as well as orchestrating them effectively in complex environments. Docker empowers developers and system administrators to streamline application deployment, enhance scalability, and improve resource utilization.

--

--

Radheya Zunjur
Radheya Zunjur

Written by Radheya Zunjur

Database Engineer At Harbinger | DevOps | Cloud Ops | Technical Writer

No responses yet