命令一
vi /usr/lib/systemd/system/docker.service
默认是:
ExecStart=/usr/bin/dockerd-current \
--add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
--default-runtime=docker-runc \
--exec-opt native.cgroupdriver=systemd \
--userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
--init-path=/usr/libexec/docker/docker-init-current \
--seccomp-profile=/etc/docker/seccomp.json \
$OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$ADD_REGISTRY \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY \
$REGISTRIES
修改为:
ExecStart=/usr/bin/dockerd-current \
--add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
--default-runtime=docker-runc \
--exec-opt native.cgroupdriver=systemd \
--userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
--init-path=/usr/libexec/docker/docker-init-current \
--seccomp-profile=/etc/docker/seccomp.json \
-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock \
$$OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$ADD_REGISTRY \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY \
$REGISTRIES
添加了一行
-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock \
然后依次执行:
systemctl daemon-reload
systemctl restart docker
可以通过命令:
netstat -tnlp|grep 2375(你设置的docker远程端口号) 查看端口号是否LISTEN
如果natstat命令不存在:
执行
yum -y install net-tools
测试配置是否成功:
执行命令:
curl 127.0.0.1:2375/info
{"ID":"DNDG:UJAL:JY7O:4OCX:7LA2:L3AN:CV6R:427E:3FWD:JWFD:SGO3:IHZ3","Containers":1,"ContainersRunning":1,"ContainersPaused":0,"ContainersStopped":0,"Images":10,"Driver":"overlay2","DriverStatus":[["Backing Filesystem","xfs"],["Supports d_type","true"],["Native Overlay Diff","true"]],"SystemStatus":null,"Plugins":{"Volume":["local"],"Network":["bridge","host","macvlan","null","overlay"],"Authorization":null},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":39,"OomKillDisable":true,"NGoroutines":52,"SystemTime":"2021-07-08T03:47:24.322619208+08:00","LoggingDriver":"journald","CgroupDriver":"systemd","NEventsListener":0,"KernelVersion":"3.10.0-862.el7.x86_64","PkgVersion":"docker-1.13.1-208.git7d71120.el7_9.x86_64","OperatingSystem":"CentOS Linux 7 (Core)","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","IndexServerName":"docker.io","RegistryConfig":{"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":null,"Secure":true,"Official":true}},"Mirrors":[]},"NCPU":4,"MemTotal":3973873664,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"10.0.3.15","Labels":null,"ExperimentalBuild":false,"ServerVersion":"1.13.1","ClusterStore":"","ClusterAdvertise":"","Runtimes":{"docker-runc":{"path":"/usr/libexec/docker/docker-runc-current"},"runc":{"path":"docker-runc"}},"DefaultRuntime":"docker-runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null,"Nodes":0,"Managers":0,"Cluster":{"ID":"","Version":{},"CreatedAt":"0001-01-01T00:00:00Z","UpdatedAt":"0001-01-01T00:00:00Z","Spec":{"Orchestration":{},"Raft":{"ElectionTick":0,"HeartbeatTick":0},"Dispatcher":{},"CAConfig":{},"TaskDefaults":{},"EncryptionConfig":{"AutoLockManagers":false}}}},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"/usr/libexec/docker/docker-init-current","ContainerdCommit":{"ID":"","Expected":"aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1"},"RuncCommit":{"ID":"66aedde759f33c190954815fb765eedc1d782dd9","Expected":"9df8b306d01f59d3a8029be411de015b7304dd8f"},"InitCommit":{"ID":"fec3683b971d9c3ef73f284f176672c44b448662","Expected":"949e6facb77383876aeff8a6944dde66b3089574"},"SecurityOptions":["name=seccomp,profile=/etc/docker/seccomp.json","name=selinux"],"Registries":[{"Name":"docker.io","Secure":true}]}
出现上述内容即认为设置成功
如果使用外部连接工具连接docker 依旧无法连接的话
查看linux防火墙,设置端口加入防火墙白名单
或者直接关闭防火墙
systemctl stop firewalld