How to restart dockerd?
Asked Answered
N

3

10

Context

In my .devcontainer that, I run in GitHub Codespaces, I've installed minikube. Shortly after minikube start I get this message

Executing "docker container inspect minikube took an unusually long time: 10.566089734s*

Restarting the docker service may improve performance.
  1. I'm using docker docker-in-docker feature.
  2. The .devcontainer environment starts docker with dockerd cli.
  3. systemctl is not present container running my environment

Question

I'd like to restart docker to improve performance. Is it possible to restart docker without stopping the docked process? Something like sudo systemctl restart docker but with dockerd?

Nb answered 1/3, 2023 at 12:23 Comment(1)
What are you trying to achieve? "Restart Docker" on bare metal would normally imply stopping and recreating the dockerd process. For things running in containers, you don't usually restart processes but rather delete and recreate the container; can you delete the DinD container?Ambrosio
L
15

To restart dockerd, restart the docker service itself. For example, sudo systemctl restart docker in ubuntu.

Lunetta answered 2/4, 2023 at 18:46 Comment(1)
Please note the third item from the OP's question.Cimbri
C
1

My initial conditions were a little different yet I think the solution still applies here.

I was creating a .devcontainer with a docker-in-docker and nvidia-cuda features enabled. I could see the GPU in the dev container but it wasn't available to the container on the second level. For that, I needed to install nvidia-container-toolkit in the first level container.

Since nvidia-container-toolkit creates a new docker runtime, this requires a dockerd restart. Default instructions would achieve this via sudo systemctl docker restart command, however, due to space constraints, sometimes systemctl isn't available.

Like the OP, I also resorted to restarting dockerd by killing the process and starting it again.

In short, I've achieved this by adding the following line to my CUDA-enabled devcontainer.json:

// Reload dockerd after installing the nvidia-container-toolkit.
"postCreateCommand": "sudo pkill dockerd && sudo pkill containerd && bash /usr/local/share/docker-init.sh",

Commands sudo pkill dockerd and sudo pkill containerd essentially terminate dockerd and containerd processes. /usr/local/share/docker-init.sh script was brought-in by ghcr.io/devcontainers/features/docker-in-docker feature, so, if you're using it, you don't need to modify the command.

However, if not, you should replace bash /usr/local/share/docker-init.sh with ( dockerd > /tmp/dockerd.log 2>&1 ) & to start dockerd process again.

Cheadle answered 5/1 at 12:48 Comment(0)
N
0

After careful studding of dockerd cli, I concluded that there is no other option of restarting the docekrd process than just killing it and starting it manually again.

Nb answered 2/3, 2023 at 21:6 Comment(1)
I deleted the comment. But yes, you are right - I didn't read the question, only the answer. To kill the docker daemon, you need to get its ID. Use ps aux | grep dockerd next kill -9 DOCKERD_ID. To start the docker daemon, manually run docked (you might run it in the background, not in the foreground, as official docs says). Please delete your comment too Thanks!Nb

© 2022 - 2024 — McMap. All rights reserved.