DEV Community

Gias Uddin
Gias Uddin

Posted on


Docker Cheat Sheet all You Need To Know About Docker Command

Docker is a platform that allows developers to create, deploy, and run applications in a containerized environment. A container is a lightweight, standalone, and executable software package that includes everything needed to run a piece of software, including the code, runtime, system tools, libraries, and settings.
Docker enables developers to package their applications and dependencies into a container, which can be easily moved between different environments, such as development, test, and production. This allows developers to ensure that their applications will run consistently across different environments, regardless of the underlying infrastructure.
Docker also provides a centralized repository called Docker Hub, where developers can store and share their container images. This allows other developers to easily download and use these images in their own applications, which can save time and effort in the development process.
Docker provides a command-line interface (CLI) that allows developers to interact with the Docker daemon, which is the process that manages the containers on a machine. Some of the commonly used Docker commands include:

1.docker version: This command displays the version of Docker that is currently installed on the machine.

2.docker pull: This command is used to download an image from Docker Hub or a private repository. The syntax for this command is docker pull , for example docker pull python. You can also specify a specific version of an image by appending the version number to the image name, for example, docker pull python:3.10-buster.

3.docker ps: This command is used to list all running containers on a machine. You can use option -a also to see containers that have been stopped.

4.docker run: This command is used to create a new container from an image. The syntax for this command is docker run , for example, docker run Redis. You can also specify additional options when running a container, such as -d to run the container in detached mode, -p to map a host port to a container port, --name to give the container a specific name, and --volume to mount a host directory as a volume in the container.

5.docker start, docker stop, docker restart: these commands are used to start, stop, and restart a container.

6.docker rm: This command is used to remove a container.
docker images: this command is used to list all the images that are currently on your machine.

7.docker logs: This command is used to view the logs of a running container. By default, it shows the logs of the latest container created, but you can specify a container name or ID to view the logs of a specific container.

8.docker exec: This command is used to run a command inside a running container. For example, docker exec -it /bin/bash would open a bash shell inside the specified container.

9.docker inspect: This command is used to view detailed information about a container or image, such as its configuration, network settings, and mounted volumes.

10.docker network: This command is used to manage Docker networks, which allow containers to communicate with each other. You can use sub-commands such as create, ls, inspect, and rm to create, list, inspect and remove networks respectively.

11.docker volume: This command is used to manage Docker volumes, which allow data to persist outside of a container's filesystem. You can use sub-commands such as create, ls, inspect, and rm to create, list, inspect and remove volumes respectively.

12.docker system prune: This command is used to remove unused data, such as stopped containers and unused images, from the host machine.

13.docker build: This command is used to build a container image from a Dockerfile. A Dockerfile is a script that contains instructions for building an image.

14.docker tag : This command allows you to assign a specific version or tag to an image. This can be useful when you want to deploy a specific version of your image to production.

15.docker push: This command is used to push an image to a registry, such as Docker Hub, so that others can download it.

These are just a few examples of the many commands that are available in Docker. It's important to note that these commands can also have additional options and parameters that can be used to customize their behavior. The official Docker documentation is a great resource for learning more

Top comments (0)