Skip to content
David Liu edited this page Mar 7, 2024 · 26 revisions

在容器管理的链路中,Docker Engine的实现就是dockerd daemon,它在linux中需要以root运行,dockerd调用containerd,containerd调用containerd-shim,然后才能调用runC。

  • containerd-shim: shim起的作用也就是“垫片”,避免父进程退出影响容器的运行
  • convention: port 2375 for raw communication
  • convention: port 2376 for TLS communication
  • No multiple dockerd in same machine simutaneously
    • failed to start daemon, ensure docker is not running or delete /var/run/docker.pid: process with PID 131867 is still running
  • image

Configure on Windows

  1. Docker Desktop: Settings -> General -> check [Expose daemon on tcp://localhost:2375 without TLS] image
  2. Click [Apply & Restart]
  3. [Workaround for Docker Desktop bug]: Quit Docker Desktop and then run it again.

Ref: https://blog.bartekr.net/2020/09/01/have-problems-with-docker-desktop-for-windows-home-yeah-me-too/

Configure on linux

https://docs.docker.com/engine/install/linux-postinstall/#configure-where-the-docker-daemon-listens-for-connections

inline config and daemon.json config are mutual exclusive

config option: inline config

/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://127.0.0.1:2375

config option: configured by daemon.json

  1. sudo vi /etc/docker/daemon.json or ~/.config/docker/daemon.json (for rootless) and edit like

    {
      ...
      "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"]
    }
    

run option: systemd (rootful)

  1. configure service sudo systemctl edit docker.service to add or modify the following lines, substituting your own values.

    [Service]
    ExecStart=
    ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 
    

    or create a docker.conf

    sudo curl https://raw.githubusercontent.com/davidkhala/linux-utils/main/apps/docker/docker.conf --create-dirs -o /etc/systemd/system/docker.service.d/docker.conf
  2. restart service

    sudo systemctl daemon-reload
    sudo systemctl restart docker.service
    

run option: direct run

  1. sudo /usr/bin/dockerd
  2. check result by sudo netstat -lntp | grep dockerd

Test

Ping the docker socket

sudo curl --unix-socket /var/run/docker.sock http://localhost/_ping

Or Ping the API endpoint

curl http://localhost:2375/_ping

Or use another docker host by specifying global flag -H

docker -H tcp://127.0.0.1:2375 ps

Clone this wiki locally