编辑/lib/systemd/system/docker.service文件,找到ExecStart行,操作如下所示:
/lib/systemd/system/docker.service
ExecStart
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock# 修改为ExecStart=/usr/bin/dockerd -H fd:// -H=tcp://0.0.0.0:2375 systemctl daemon-reload && systemctl restart docker# 测试访问curl localhost:2375/images/json
远程访问之前可以做好SSH免密,在此就不再赘述。
DOCKER_HOST
例如使用docker-compose时要连接远程docker:
docker-compose
$ DOCKER_HOST="ssh://user@remotehost" docker-compose up -d
列出当前主机的Docker 上下文:
Docker 上下文
$ docker context lsNAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATORdefault * Current DOCKER_HOST based configuration unix:///var/run/docker.sock https://127.0.0.1:6443 (default) swarm
创建一个新的上下文:
$ docker context create remote ‐‐docker "host=ssh://root@woniu"# 或者使用tcp进行连接# docker context create remote --docker "host=tcp://IP:PORT"remoteSuccessfully created context “remote”
临时使用:
$ docker ‐‐context remote psCONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
切换当前上下文:
$ docker context use remoteremoteCurrent context is now "remote"