一、常见Docker端口
2375:未加密的docker socket,远程root无密码访问主机
2376:tls加密套接字,很可能这是您的CI服务器4243端口作为https 443端口的修改
2377:群集模式套接字,适用于群集管理器,不适用于docker客户端
5000:docker注册服务
4789和7946:覆盖网络
二、Docker端口开放方式一
#1.配置开放端口2375
[root@stg-databridge001 ~]# vim /etc/default/docker
DOCKER_OPTS="-H tcp://0.0.0.0:2375"
#2.重启Docker
[root@stg-databridge001 ~]# systemctl restart docker
#3.验证端口
[root@stg-databridge001 ~]# netstat -lntp |grep 2375
tcp6 0 0 :::2375 :::* LISTEN 27185/dockerd
ps:这是网上给的配置方法,也是这种简单配置让Docker Daemon把服务暴露在tcp的2375端口上,这样就可以在网络上操作Docker了。Docker本身没有身份认证的功能,只要网络上能访问到服务端口,就可以操作Docker。
三、Docker端口开放方式二
在/usr/lib/systemd/system/docker.service,配置远程访问。
#1.主要是在[Service]这个部分,加上参数
[root@stg-databridge001 ~]# vim /usr/lib/systemd/system/docker.service
... ...
[Service]
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock --graph=/data/docker_data/docker
#2.重载system
[root@stg-databridge001 ~]# systemctl daemon-reload
#3.重启Docker
[root@stg-databridge001 ~]# systemctl restart docker
#4.验证Docker
[root@stg-databridge001 ~]$ ps -ef |grep docker
root 27185 1 0 14:46 ? 00:00:00 /usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock --graph=/data/docker_data/docker
四、Docker端口开放方式三
#1.添加配置
[root@stg-databridge001 ~]# vim /etc/docker/daemon.json
{
"hosts": ["tcp://0.0.0.0:2375"]
}
#2.修改启动服务文件
[root@stg-databridge001 ~]# vim /usr/lib/systemd/system/docker.service
... ...
[Service]
ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock --graph=/data/docker_data/docker
#3.重新读取配置文件,并重启docker服务
systemctl daemon-reload
systemctl restart docker
#4.查看docker进程:
[root@stg-databridge001 ~]$ ps -ef |grep docker
root 27185 1 0 14:46 ? 00:00:00 /usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock --graph=/data/docker_data/docker
ps:#一定要修改docker.service,否则会冲突,然后启动报错:
unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the configuration file: hosts: (from flag: [fd://], from file: [tcp://0.0.0.0:2375, unix:///var/run/docker.socket])
五、简单使用
-H为连接目标主机docker服务
#1.查看docker版本
[root@staging conf]# docker -H tcp://68.79.54.195:2375 version
Client: Docker Engine - Community
Version: 20.10.11
API version: 1.41
Go version: go1.16.9
Git commit: dea9396
Built: Thu Nov 18 00:38:53 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.11
API version: 1.41 (minimum version 1.12)
Go version: go1.16.9
Git commit: 847da18
Built: Thu Nov 18 00:37:17 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
#2.查看镜像包
[root@staging conf]# docker -H tcp://68.79.54.195:2375 images
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins/jenkins lts 2a4bbe50c40b 6 weeks ago 441MB
hub.dataxhotel.com/mjn/mjn-data-bridge latest f43633ebd6e1 42 years ago 263MB