OneBite.Dev - Coding blog in a bite size

stop docker

Simple docker step by step how to stop docker with explanation

Docker is a tool that creates an environment for developers to build and distribute applications effectively. This article will guide you through the process of stopping a Docker container.

Getting Started

The first thing you need is Docker, which must already be installed and be running on your computer. If you haven’t installed Docker yet, you can find the instructions for your operating system on the official Docker website.

Step 1: Identifying the Docker Process

To stop a Docker container, you need to know the container ID or the container name. List all the running Docker containers on your system using the docker ps command.

Open a terminal and type the following command:

docker ps

This command will list all running Docker containers along with some details, like CONTAINER ID, IMAGE, COMMAND, CREATED, STATUS, PORTS, and NAMES.

The CONTAINER ID and NAME are vital for the next step.

Step 2: Stopping the Docker Container

After you’ve identified the Docker container that you want to stop, you can stop it by using the docker stop command followed by the container ID or the container name.

For example, if the CONTAINER ID is a1b2c3d4, type the following command in the terminal:

docker stop a1b2c3d4

Alternatively, you can also use the NAME of the Docker container. If the NAME is my_container, then input the following command:

docker stop my_container

The docker stop command tries to stop the container gracefully at first, and if it does not work, it forcefully stops the Docker container after a set duration.

Conclusion

Stopping a Docker container is a simple process. You only need to know the details of the Docker container you intend to stop. It’s essential to note that once you stop a Docker container, all the data inside it that is not stored elsewhere will be lost. Therefore, always ensure that you back up your data if it is required in the future. Remember to use the docker ps command to view the running Docker containers and the docker stop command to actually halt a running Docker process.

docker