Docker

How do I Restart Docker Without Stopping Containers?

Docker is a well-liked, free-of-cost, and open-source forum that is utilized globally for building, deploying, and sharing applications. The Docker platform works with different components, but most of the Docker processing is done through the Docker engine or Docker daemon. Docker Daemon is responsible for managing and running the images and containers on the host.

Sometimes, some processes are stuck while running the container. This may be due to a problem with the network or Docker engine. For this purpose, restarting Docker can resolve this kind of issue.

This write-up will demonstrate how to restart Docker without stopping containers.

How do I Restart Docker Without Stopping Containers?

When the Docker users stop or restart the Docker, it will only restart the Docker Daemon, not the containers. In Windows, containers are executed as a separate process. So running containers cannot be terminated or stopped when the Docker engine stops:

For the demonstration, go through the provided instructions.

Step 1: Create Compose File
First, create a compose file to run multiple services in containers. For instance, we will execute the “go-img” that containerized the Golang project:

version: "alpine"
services:
  web:
    container_name: web-container
    image: go-img
    command: ["./webserver"]
    ports:
      - "8080:8080/tcp"
  golang:
    image: "golang:alpine"

Step 2: Start Docker Container
Next, create and start the container in Docker compose using the given command. Here, “-d” will execute the services or containers in the background:

> docker-compose up -d

For confirmation if the container is executing or not, visit the specified port of the local host. For instance, we have navigated to the “8080”:

Step 3: Open Windows PowerShell
Launch the Windows PowerShell as an administrator from the Start menu:

Step 4: Restart Docker Service
Restart the Docker engine by restarting the Docker service with the help of the “Restart-Service Docker” command:

> Restart-Service Docker

Verify if the service is restarted or not through “Get-Service Docker” command:

> Get-Service Docker

Here, you can see we have successfully restart the Docker:

Again, navigate to the local host port where your container is running:

You can see that from the above output, the container is not terminated when we have restarted the Docker service.

Conclusion

In Windows, when the Docker service is restarted, it will not affect or stop the Docker container. Because containers are executed as a separate process. First, run Windows PowerShell as an administrator to restart the Docker service. After that, execute the “Restart-Service Docker” command to restart the Docker service. This article has demonstrated how to restart Docker without stopping containers.

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.