docker开启远程访问

docker开启远程访问

系统使用centos7

一、打开docker端口

/usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd-current \
#增加-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock  重启docker
ExecStart=/usr/bin/dockerd-current -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock \

之后重启docker让配置生效。
即可通过http方式和docker -H方式访问docker

二、命令测试

134上运行的容器

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
4f191cbd3c26        redis               "docker-entrypoint..."   6 months ago        Up 9 hours          0.0.0.0:6379->6379/tcp   some-redis
6de8887c05fa        mysql               "docker-entrypoint..."   6 months ago        Up 9 hours          0.0.0.0:3308->3306/tcp   mysql8
60d325c743c4        mysql-57            "container-entrypo..."   6 months ago        Up 9 hours          0.0.0.0:3306->3306/tcp   mysql57

134已打开远程端口。通过137查看134的容器和137自己的容器

[root@docker137 ~]# docker -H 192.168.72.134 ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
4f191cbd3c26        redis               "docker-entrypoint..."   6 months ago        Up 9 hours          0.0.0.0:6379->6379/tcp   some-redis
6de8887c05fa        mysql               "docker-entrypoint..."   6 months ago        Up 9 hours          0.0.0.0:3308->3306/tcp   mysql8
60d325c743c4        mysql-57            "container-entrypo..."   6 months ago        Up 9 hours          0.0.0.0:3306->3306/tcp   mysql57
[root@docker137 ~]# docker ps
CONTAINER ID        IMAGE                              COMMAND                  CREATED             STATUS                        PORTS                       NAMES
d9f65ddf94eb        vmware/nginx-photon:v1.5.1         "nginx -g 'daemon ..."   6 months ago        Restarting (1) 30 hours ago                               nginx
4b363df62d6a        vmware/harbor-adminserver:v1.5.1   "/harbor/start.sh"       6 months ago        Up 34 hours (healthy)                                     harbor-adminserver
fd13295da8db        vmware/harbor-db:v1.5.1            "/usr/local/bin/do..."   6 months ago        Up 34 hours (healthy)         3306/tcp                    harbor-db
46fd5560d00e        vmware/harbor-log:v1.5.1           "/bin/sh -c /usr/l..."   6 months ago        Up 34 hours (healthy)         127.0.0.1:1514->10514/tcp   harbor-log

136服务器未打开端口,响应错误提示信息

[root@localhost ~]#  docker -H 192.168.72.136 ps
error during connect: Get http://192.168.72.136:2375/v1.26/containers/json: dial tcp 192.168.72.136:2375: getsockopt: no route to host

你可能感兴趣的:(docker)