欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

CentOS上开启Docker远程访问

时间:2023-05-18
CentOS上开启Docker远程访问

1.修改/etc/systemd/system//docker.service

直接在ExecStart后面追加  -H unix:///var/run/docker.sock -H 0.0.0.0:2375

[Unit]Description=Docker Application Container Enginedocumentation=http://docs.docker.io[Service]WorkingDirectory=/data/dockerEnvironment="PATH=/opt/docker/bin:/bin:/sbin:/usr/bin:/usr/sbin"ExecStart=/opt/docker/bin/dockerd -H unix:///var/run/docker.sock -H 0.0.0.0:2375ExecReload=/bin/kill -s HUP $MAINPIDRestart=on-failureRestartSec=5LimitNOFILE=infinityLimitNPROC=infinityLimitCORE=infinityDelegate=yesKillMode=process[Install]WantedBy=multi-user.target

2.重启docker,让配置生效

# systemctl daemon-reload# systemctl restart docker.service

3.用netstat -lntp | grep 2375 查看配置是否生效

netstat -lntp | grep 2375

 4.使用curl进行测试

curl 127.0.0.1:2375/info

[root@iZwz99xeomvq1omj9cu7tuZ system]# curl 127.0.0.1:2375/info{"ID":"CN5P:W2Y7:2FV6:OY4U:CFS4:WYDC:DJ4N:VXZI:PTNR:BHTD:FRHR:VE27","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":0,"Driver":"overlay2","DriverStatus":[["Backing Filesystem","xfs"],["Supports d_type","true"],["Native Overlay Diff","true"],["userxattr","false"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","ipvlan","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","local","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"KernelMemoryTCP":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":true,"NFd":25,"OomKillDisable":true,"NGoroutines":42,"SystemTime":"2022-02-17T16:57:12.093571887+08:00","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","CgroupVersion":"1","NEventsListener":1,"KernelVersion":"4.18.0-240.22.1.el8_3.x86_64","OperatingSystem":"CentOS Linux 8","OSVersion":"8","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":[],"AllowNondistributableArtifactsHostnames":[],"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":["https://477njxek.mirror.aliyuncs.com/","https://registry.docker-cn.com/","https://hub-mirror.c.163.com/","https://docker.mirrors.ustc.edu.cn/"],"Secure":true,"Official":true}},"Mirrors":["https://477njxek.mirror.aliyuncs.com/","https://registry.docker-cn.com/","https://hub-mirror.c.163.com/","https://docker.mirrors.ustc.edu.cn/"]},"NCPU":8,"MemTotal":33513316352,"GenericResources":null,"DockerRootDir":"/data/docker/data","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"server1","Labels":[],"ExperimentalBuild":false,"ServerVersion":"20.10.7","Runtimes":{"io.containerd.runc.v2":{"path":"runc"},"io.containerd.runtime.v1.linux":{"path":"runc"},"runc":{"path":"runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":true,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"d71fcd7d8303cbf684402823e425e9dd2e99285d","Expected":"d71fcd7d8303cbf684402823e425e9dd2e99285d"},"RuncCommit":{"ID":"b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7","Expected":"b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7"},"InitCommit":{"ID":"de40ad0","Expected":"de40ad0"},"SecurityOptions":["name=seccomp,profile=default"],"ProductLicense":"Community Engine","Warnings":["WARNING: API is accessible on http://0.0.0.0:2375 without encryption.n Access to the remote API is equivalent to root access on the host、Refern to the 'Docker daemon attack surface' section in the documentation forn more information: https://docs.docker.com/go/attack-surface/"]}

5.开放2375端口

firewall-cmd --permanent --add-port=2375/tcp --zone=publicsystemctl restart firewalld.service

在window上打开命令行输入

C:UsersAdministrator>curl http://120.75.13.123:2375/info{"ID":"CN5P:W2Y7:2FV6:OY4U:CFS4:WYDC:DJ4N:VXZI:PTNR:BHTD:FRHR:VE27","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":0,"Driver":"overlay2","DriverStatus":[["Backing Filesystem","xfs"],["Supports d_type","true"],["Native Overlay Diff","true"],["userxattr","false"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","ipvlan","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","local","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"KernelMemoryTCP":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":true,"NFd":24,"OomKillDisable":true,"NGoroutines":40,"SystemTime":"2022-02-17T16:51:30.813638631+08:00","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","CgroupVersion":"1","NEventsListener":0,"KernelVersion":"4.18.0-240.22.1.el8_3.x86_64","OperatingSystem":"CentOS Linux 8","OSVersion":"8","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":[],"AllowNondistributableArtifactsHostnames":[],"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":["https://477njxek.mirror.aliyuncs.com/","https://registry.docker-cn.com/","https://hub-mirror.c.163.com/","https://docker.mirrors.ustc.edu.cn/"],"Secure":true,"Official":true}},"Mirrors":["https://477njxek.mirror.aliyuncs.com/","https://registry.docker-cn.com/","https://hub-mirror.c.163.com/","https://docker.mirrors.ustc.edu.cn/"]},"NCPU":8,"MemTotal":33513316352,"GenericResources":null,"DockerRootDir":"/data/docker/data","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"server1","Labels":[],"ExperimentalBuild":false,"ServerVersion":"20.10.7","Runtimes":{"io.containerd.runc.v2":{"path":"runc"},"io.containerd.runtime.v1.linux":{"path":"runc"},"runc":{"path":"runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":true,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"d71fcd7d8303cbf684402823e425e9dd2e99285d","Expected":"d71fcd7d8303cbf684402823e425e9dd2e99285d"},"RuncCommit":{"ID":"b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7","Expected":"b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7"},"InitCommit":{"ID":"de40ad0","Expected":"de40ad0"},"SecurityOptions":["name=seccomp,profile=default"],"ProductLicense":"Community Engine","Warnings":["WARNING: API is accessible on http://0.0.0.0:2375 without encryption.n Access to the remote API is equivalent to root access on the host、Refern to the 'Docker daemon attack surface' section in the documentation forn more information: https://docs.docker.com/go/attack-surface/"]}

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。