栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

CentOS上开启Docker远程访问

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CentOS上开启Docker远程访问

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 Engine
documentation=http://docs.docker.io

[Service]
WorkingDirectory=/data/docker
Environment="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:2375
ExecReload=/bin/kill -s HUP $MAINPID
Restart=on-failure
RestartSec=5
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Delegate=yes
KillMode=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=public
systemctl 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/"]}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/740854.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号