On the Docker platform, all processing of projects is done in Docker containers. Docker containers are used to manage and run projects. These containers are processed by various commands, and “docker start” and “docker restart” are one of the most used command line utilities to start or run Docker containers.
This blog will demonstrate how to restart a Docker container.
How to Restart Container Using “docker restart” Command?
The docker restart command is mostly used to start the stopped containers. To restart the container, utilize the “docker restart <container-id>” command.
Go through the provided instructions to restart the Docker container.
Step 1: Create Docker Container
First, create a fresh container from the Docker image by utilizing the provided command. Here:
- “-i” is used to create a container in interactive mode.
- “-p” is used to specify the port where the container will execute.
- “–name” is utilized to define the container name:
Step 2: Start Container
After creating a container, start the container through the “docker start <container-name>” command:
Now, navigate to the specified port on the browser. In our scenario, we have navigated the “http://localhost:8080” URL on the browser:
Step 3: Stop Docker Container
To stop the container, users can utilize the “docker stop <container-name>” command:
Step 4: List Docker Container
List all the docker containers using the “docker ps” command. After that, note the container if you want to restart. Here, the “-a” option is used to list all containers:
Step 5: Restart Docker Container
Next, restart the stopped container with the help of the “docker restart <container-id>” command:
Alternatively, you can also utilize the container name with the “docker restart” command to restart the container by name:
Here, you can see we successfully restart the container:
Note: The “docker restart” is a shorthand command of “docker container restart”. Users can also execute the “docker container restart” command to restart containers:
Conclusion
The “docker restart” is a shorthand command of “docker container restart” that is used to restart or start the Docker containers. To restart the Docker containers, the user can utilize the “docker start” or “docker restart <container-name>” command. This write-up has elaborated on the “docker restart” command and how to restart the container.