Docker containers are simple, lightweight executable packages to execute programs and projects. A Docker container contains everything required to run an application, such as program code, dependencies, packages, system tools, and required settings. Docker containers are also helpful for the shipment of applications and software. When working with Docker containers, the users must know basic commands to create, start, and stop the container.
This tutorial will demonstrate how to start and stop the containers in Docker.
How to Start and Stop the Container in Docker?
While building applications in Docker containers, developers usually need to start and stop the containers for testing and application deployment. For this purpose, check out the instructions to start and stop the containers in Docker.
Step 1: Build Docker Container
First, build a Docker container by utilizing the Docker image. For this purpose, use the “docker create” command as follows:
Here:
-
- “-i” is utilized to build a container in interactive mode.
- “-p” defines the port to execute the container.
- “–name” is used to define the name for the container:
Step 2: Start Container
After that, start the container to deploy a containerized application using the “docker start <container-name>” command:
Now, visit the port on which you have executed the Docker container. For instance, we have navigated to the “http://localhost:8080” URL:
Step 3: Stop Docker Container
In order to stop running containers in Docker, utilize the “docker stop <container-name>” command:
Step 4: List Docker Container
Users can also start or stop the containers in Docker through container id. To find out the container id, list the detailed information about docker containers using the “docker ps -a” command:
We have taught you the method to create, start and stop the Docker container.
Conclusion
To start the containers, first, create a fresh container through the “docker create” command. After that, start the Docker container to execute it on a specified port using the “docker start <container-name>” command. To stop the Docker container, simply use the “docker stop <container-name>” command. However, users can also use the container id to start or stop the containers in Docker. This blog has illustrated the procedure to start and stop the containers in Docker.