Docker

How do I Start and Stop Docker Container

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:

> docker container create -i -p 8080:8080 --name docker-container dockerimage

 
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:

> docker start docker-container

 

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:

> docker stop docker-container

 

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:

> docker ps -a

 

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.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.