Подключение к удаленному Docker-демону - PullRequest
0 голосов
/ 14 мая 2019

Я установил VirtualBox и установил версию сервера Ubuntu в VirtualBox VM. Мой хост-компьютер - Windows 10.

Я также установил Docker в свой хост-компьютер Windows. Я намерен использовать интерфейс командной строки докера в Windows для подключения к демону докера (серверу) внутри виртуальной машины.

Я внес изменения в виртуальную машину Ubuntu, и она прослушивает порт 2375.

tcp        0      0 127.0.0.1:2375          0.0.0.0:*                LISTEN 2305/dockerd

Также я установил переменную окружения DOCKER_HOST на моем хосте (Windows) для IP-адреса и порта машины ВМ.

 set DOCKER_HOST=tcp://192.168.56.107:2375

IP-адрес моей машины с Windows - 192.168.56.1, и пинг работает нормально.

Pinging 192.168.56.107 with 32 bytes of data:
Reply from 192.168.56.107: bytes=32 time<1ms TTL=64
Reply from 192.168.56.107: bytes=32 time<1ms TTL=64

Но когда я пытаюсь подключиться с моего компьютера с Windows, выдается следующая ошибка:

error during connect: Get http://192.168.56.107:2375/v1.27/info: dial tcp 192.168.56.107:2375: connectex: No connection could be made because the target machine actively refused it.

Пожалуйста, найдите вывод информации о докере:

controller@ubuntuserver:~$ docker info
Containers: 4
 Running: 0
 Paused: 0
 Stopped: 4
Images: 2
Server Version: 18.09.6
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84
runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30
init version: fec3683
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.15.0-50-generic
Operating System: Ubuntu 18.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 7.79GiB
Name: ubuntuserver
ID: AWDW:34ET:4J2J:2NWB:UPK7:EQHB:W64E:22AT:W6J4:BMRD:NDO6:CNR2
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

WARNING: API is accessible on http://127.0.0.1:2375 without encryption.
         Access to the remote API is equivalent to root access on the host. Refer
         to the 'Docker daemon attack surface' section in the documentation for
         more information: https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
WARNING: No swap limit support

 cat /lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process

[Install]
WantedBy=multi-user.target

Не могли бы вы помочь мне решить эту проблему?

Ответы [ 2 ]

1 голос
/ 17 мая 2019

Вам необходимо настроить демон Docker на вашем сервере Ubuntu, чтобы он мог принимать tcp-соединение. По умолчанию Docker прослушивает сокет unix /var/run/docker.sock. Чтобы настроить своего демона, вы можете взглянуть на документацию здесь

Пошаговая настройка (в этом примере все делается на Ubuntu VM ):

Настройка демона
В Ubuntu по умолчанию вы используете systemd. Вам необходимо отредактировать файл конфигурации (обычно находится в /lib/systemd/system/docker.service):

[Service]
ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375

В этом примере демон Docker больше не прослушивает сокет unix. Он только слушает tcp-вызов с localhost.
Перезапустите демон:

$> sudo systemctl daemon-reload
$> sudo systemctl restart docker.service

Настройка клиента (все еще на виртуальной машине)
После перезапуска демона ваш док-клиент больше не работает (как вы только что сказали клиенту прослушивать только tcp-соединение). Таким образом, если вы делаете docker image ls, он не должен отвечать. Чтобы ваш клиент работал, вам нужно указать ему, к какому серверу подключаться:

$> export DOCKER_HOST="tcp://0.0.0.0:2375"

Теперь ваш клиент должен иметь возможность подключиться к демону (т.е.: docker image ls должен распечатать все изображения)

Это должно нормально работать на вашем сервере Ubuntu. Вам просто нужно применить ту же конфигурацию клиента в Windows. Если он не работает в Windows, значит, что-то еще блокирует трафик (возможно, брандмауэр).

Надеюсь, это поможет.

0 голосов
/ 29 мая 2019

Разрешено с помощью этой ссылки .

Хотя порт нужно изменить на 2376.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...