,

docker CLI Cheat Sheet Summary

Posted by

This article provides a Docker cheat sheet for using Docker’s command-line interface (CLI). It includes commands for building, managing, and running Docker images and containers, as well as accessing Docker Hub and other useful features. Docker is a platform that allows you to package and run applications in isolated containers.

What is Docker and what is its purpose

Docker is a platform that allows you to package and run applications in isolated containers. Its purpose is to provide the ability to run an application in a loosely isolated environment called a container. This isolation and security enable running many containers simultaneously on a given host. Containers are lightweight and contain everything needed to run the application, eliminating the reliance on what is currently installed on the host. Additionally, Docker allows for easy sharing of containers while ensuring that everyone receives the same working container.

How to run and manage Docker containers

To run and manage Docker containers, you can use a variety of commands. To create and run a container from an image with a custom name, you can use the command:

docker run --name <container_name> <image_name>

To run a container and publish its port(s) to the host, you can use the following command:

docker run -p <host_port>:<container_port> <image_name>

If you want to run a container in the background, you can use the command:

docker run -d <image_name>

To start or stop an existing container, you can use the commands:

docker start <container_name> (or <container-id>)
docker stop <container_name> (or <container-id>)

To remove a stopped container, you can use the command:

docker rm <container_name>

If you need to open a shell inside a running container, you can use the command:

docker exec -it <container_name> sh

And if you want to fetch and follow the logs of a container, you can use the command:

docker logs -f <container_name>

These commands allow you to effectively run and manage Docker containers based on your specific needs.

How to build an image from a Dockerfile

To build an image from a Dockerfile, you can use the following command:

docker build -t <image_name>

This command allows you to build an image from a Dockerfile with the specified image name. Additionally, if you want to build an image from a Dockerfile without using the cache, you can use the command:

docker build -t <image_name> . --no-cache

These commands provide the necessary steps to build an image from a Dockerfile.

Docker is a platform that allows you to package and run applications in isolated containers. Its purpose is to provide the ability to run an application in a loosely isolated environment called a container. This isolation and security enable running many containers simultaneously on a given host. Containers are lightweight and contain everything needed to run the application, eliminating the reliance on what is currently installed on the host. Additionally, Docker allows for easy sharing of containers while ensuring that everyone receives the same working container.

Leave a Reply

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