Ubuntu中Docker的远程访问

来源:互联网 发布:淘宝平台商品标价问题 编辑:程序博客网 时间:2024/06/14 00:06

 

查看docker版本信息(2.9机器上)

root@ubuntu:~# docker version

Client version: 1.6.2

Client API version: 1.18

Go version (client): go1.2.1

Git commit (client): 7c8fca2

OS/Arch (client): linux/amd64

Server version: 1.6.2

Server API version: 1.18

Go version (server): go1.2.1

Git commit (server): 7c8fca2

OS/Arch (server): linux/amd64

 

 

 

测试unix:///var/run/docker.sock链接方式(2.9机器上)

root@ubuntu:~#nc -U /var/run/docker.sock

GET/info HTTP/1.1

 

HTTP/1.1 200 OK

Content-Type: application/json

Job-Name: info

Date: Sat, 01 Jul 2017 12:27:33 GMT

Content-Length: 897

 

{"Containers":4,"Debug":0,"DockerRootDir":"/var/lib/docker","Driver":"aufs","DriverStatus":[["RootDir","/var/lib/docker/aufs"],["Backing Filesystem","extfs"],["Dirs","19"],["Dirperm1Supported","true"]],"ExecutionDriver":"native-0.2","ID":"RYLL:54NR:2IOC:AUGN:RFJJ:N7OV:4TZL:NCD5:MSSN:4OO5:2ZOJ:D6AT","IPv4Forwarding":1,"Images":11,"IndexServerAddress":"https://index.docker.io/v1/","InitPath":"/usr/lib/docker.io/dockerinit","InitSha1":"22082e594df367c79a11672c59a9d5da15851227","KernelVersion":"4.2.0-27-generic","Labels":null,"MemTotal":2079969280,"MemoryLimit":1,"NCPU":1,"NEventsListener":0,"NFd":14,"NGoroutines":14,"Name":"ubuntu","OperatingSystem":"Ubuntu14.04.4LTS","RegistryConfig":{"IndexConfigs":{"docker.io":{"Mirrors":null,"Name":"docker.io","Official":true,"Secure":true}},"InsecureRegistryCIDRs":["127.0.0.0/8"]},"SwapLimit":0,"SystemTime":"2017-07-01T05:27:33.48953141-07:00"}

 

HTTP/1.1 400 Bad Request

root@ubuntu:~#

root@ubuntu:~#ll /var/run/docker.sock

srw-rw---- 1 root docker 0 Jul  1 05:14 /var/run/docker.sock=

root@ubuntu:~#

root@ubuntu:~# status docker

root@ubuntu:~# service docker stop

root@ubuntu:~# status docker

root@ubuntu:~# service docker start

root@ubuntu:~# service docker restart

 

 

 

修改/etc/default/docker配置文件(2.9机器上)

root@ubuntu:~#vim /etc/default/docker

......

DOCKER_OPTS="--label name=docker_server_1"

......

 

root@ubuntu:~#service docker restart

root@ubuntu:~# ps -ef|grep docker

root     12236      1  6 05:42 ?        00:00:00 /usr/bin/docker -d --labelname=docker_server_1

root     12277   8863  0 05:42 pts/1    00:00:00 grep --color=auto docker

root@ubuntu:~#docker info

Containers: 4

Images: 11

Storage Driver: aufs

 Root Dir:/var/lib/docker/aufs

 BackingFilesystem: extfs

 Dirs: 19

 Dirperm1Supported: true

Execution Driver: native-0.2

Kernel Version: 4.2.0-27-generic

Operating System: Ubuntu 14.04.4 LTS

CPUs: 1

Total Memory: 1.937 GiB

Name: ubuntu

ID: RYLL:54NR:2IOC:AUGN:RFJJ:N7OV:4TZL:NCD5:MSSN:4OO5:2ZOJ:D6AT

WARNING: No swap limit support

Labels:

 name=docker_server_1

root@ubuntu:~#

root@ubuntu:~#

 

 

 

 

docker服务端采用tcp的方式连接(2.9机器上)

root@ubuntu:~# vim /etc/default/docker

root@ubuntu:~# cat /etc/default/docker

DOCKER_OPTS="--label name=docker_server_1 -Htcp://0.0.0.0:2375"

root@ubuntu:~#

root@ubuntu:~# service docker restart

root@ubuntu:~# ps -ef|grep docker

root      2521      1  2 06:25 ?        00:00:00 /usr/bin/docker -d --labelname=docker_server_1 -H tcp://0.0.0.0:2375

root       2559  2347  0 06:25 pts/1    00:00:00 grep --color=auto docker

root@ubuntu:~#

 

 

安装docker(2.10机器上)

root@ubuntu:~#uname -a

Linux ubuntu 4.2.0-27-generic #32~14.04.1-UbuntuSMP Fri Jan 22 15:32:26 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

root@ubuntu:~# ls -l/sys/class/misc/device-mapper 

lrwxrwxrwx 1 root root 0 Jul  1 05:56 /sys/class/misc/device-mapper ->../../devices/virtual/misc/device-mapper

root@ubuntu:~#apt-get install docker.io 

root@ubuntu:~#docker run ubuntu echo 'Hello World!'

Hello World!

root@ubuntu:~#docker images

REPOSITORY         TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

ubuntu             latest             dc8dd8718e57        10 daysago         119.2 MB

 

root@ubuntu:~#docker info

Containers: 1

Images: 6

Storage Driver: aufs

 Root Dir:/var/lib/docker/aufs

 BackingFilesystem: extfs

 Dirs: 8

 Dirperm1Supported: true

Execution Driver: native-0.2

Kernel Version: 4.2.0-27-generic

Operating System: Ubuntu 14.04.4 LTS

CPUs: 1

Total Memory: 1.937 GiB

Name: ubuntu

ID:ZMIO:CQD2:CT7E:JZEI:TXLG:BTM7:VMP5:ZDDO:DHGO:JB2J:NEWG:CW6D

WARNING: No swap limit support

root@ubuntu:~#

 

 

编辑/etc/default/docker配置文件(2.10机器上)

root@ubuntu:~#vim /etc/default/docker

......

DOCKER_OPTS="--labelname=docker_server_2"

......

root@ubuntu:~#service docker restart

docker stop/waiting

docker start/running, process 5471

root@ubuntu:~# docker info

Containers: 1

Images: 6

Storage Driver: aufs

 Root Dir:/var/lib/docker/aufs

 BackingFilesystem: extfs

 Dirs: 8

 Dirperm1Supported: true

Execution Driver: native-0.2

Kernel Version: 4.2.0-27-generic

Operating System: Ubuntu 14.04.4 LTS

CPUs: 1

Total Memory: 1.937 GiB

Name: ubuntu

ID:ZMIO:CQD2:CT7E:JZEI:TXLG:BTM7:VMP5:ZDDO:DHGO:JB2J:NEWG:CW6D

WARNING: No swap limit support

Labels:

 name=docker_server_2

root@ubuntu:~#

 

root@ubuntu:~#curl http://192.168.2.9:2375/info

{"Containers":4,"Debug":0,"DockerRootDir":"/var/lib/docker","Driver":"aufs","DriverStatus":[["RootDir","/var/lib/docker/aufs"],["BackingFilesystem","extfs"],["Dirs","19"],["Dirperm1Supported","true"]],"ExecutionDriver":"native-0.2","ID":"RYLL:54NR:2IOC:AUGN:RFJJ:N7OV:4TZL:NCD5:MSSN:4OO5:2ZOJ:D6AT","IPv4Forwarding":1,"Images":11,"IndexServerAddress":"https://index.docker.io/v1/","InitPath":"/usr/lib/docker.io/dockerinit","InitSha1":"22082e594df367c79a11672c59a9d5da15851227","KernelVersion":"4.2.0-27-generic","Labels":["name=docker_server_1"],"MemTotal":2079969280,"MemoryLimit":1,"NCPU":1,"NEventsListener":0,"NFd":14,"NGoroutines":14,"Name":"ubuntu","OperatingSystem":"Ubuntu14.04.4 LTS","RegistryConfig":{"IndexConfigs":{"docker.io":{"Mirrors":null,"Name":"docker.io","Official":true,"Secure":true}},"InsecureRegistryCIDRs":["127.0.0.0/8"]},"SwapLimit":0,"SystemTime":"2017-07-01T06:26:37.042904804-07:00"}

root@ubuntu:~#

 

 

docker远程访问-修改客户端配置(2.10机器上)

root@ubuntu:~#export DOCKER_HOST="tcp://192.168.2.9:2375"

root@ubuntu:~#docker info

Containers: 4

Images: 11

Storage Driver: aufs

 Root Dir:/var/lib/docker/aufs

 BackingFilesystem: extfs

 Dirs: 19

 Dirperm1Supported: true

Execution Driver: native-0.2

Kernel Version: 4.2.0-27-generic

Operating System: Ubuntu 14.04.4 LTS

CPUs: 1

Total Memory: 1.937 GiB

Name: ubuntu

ID:RYLL:54NR:2IOC:AUGN:RFJJ:N7OV:4TZL:NCD5:MSSN:4OO5:2ZOJ:D6AT

WARNING: No swap limit support

Labels:

 name=docker_server_1

root@ubuntu:~#

 

 

 

取消远程访问(2.10机器上)

root@ubuntu:~#export DOCKER_HOST=""

root@ubuntu:~#docker info

Containers: 1

Images: 6

Storage Driver: aufs

 Root Dir:/var/lib/docker/aufs

 BackingFilesystem: extfs

 Dirs: 8

 Dirperm1Supported: true

Execution Driver: native-0.2

Kernel Version: 4.2.0-27-generic

Operating System: Ubuntu 14.04.4 LTS

CPUs: 1

Total Memory: 1.937 GiB

Name: ubuntu

ID:ZMIO:CQD2:CT7E:JZEI:TXLG:BTM7:VMP5:ZDDO:DHGO:JB2J:NEWG:CW6D

WARNING: No swap limit support

Labels:

 name=docker_server_2

root@ubuntu:~#

 

 

 

在服务端设置unix和tcp2中连接方式(2.9机器上)

 

查看docker信息-异常(2.9机器上):

root@ubuntu:~#docker info

FATA[0000] Gethttp:///var/run/docker.sock/v1.18/info: dial unix /var/run/docker.sock: no suchfile or directory. Are you trying to connect to a TLS-enabled daemon withoutTLS?

root@ubuntu:~#

处理方法

root@ubuntu:~#vim /etc/default/docker tcp

root@ubuntu:~#cat /etc/default/docker

......

DOCKER_OPTS="--label name=docker_server_1 -H tcp://0.0.0.0:2375 -Hunix:///var/run/docker.sock"

......

root@ubuntu:~#

root@ubuntu:~#service docker restart

root@ubuntu:~#docker info

Containers: 4

Images: 11

Storage Driver: aufs

 Root Dir:/var/lib/docker/aufs

 BackingFilesystem: extfs

 Dirs: 19

 Dirperm1Supported: true

Execution Driver: native-0.2

Kernel Version: 4.2.0-27-generic

Operating System: Ubuntu 14.04.4 LTS

CPUs: 1

Total Memory: 1.937 GiB

Name: ubuntu

ID: RYLL:54NR:2IOC:AUGN:RFJJ:N7OV:4TZL:NCD5:MSSN:4OO5:2ZOJ:D6AT

WARNING: No swap limit support

Labels:

 name=docker_server_1

root@ubuntu:~#