4

I have installed VirtualBox and installed Ubuntu server version in VirtualBox VM. My host machine is Windows 10.

I have also installed Docker in my host Windows box. My intention is to use the docker CLI in Windows to connect to docker daemon (server) inside the VM.

I have made the changes in the Ubuntu VM and it is listening at port 2375.

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

Also I have set the environment variable DOCKER_HOST in my host(Windows) to the VM machine IP and port.

 set DOCKER_HOST=tcp://192.168.56.107:2375

My Windows machine IP is 192.168.56.1 and the ping is working fine.

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

But when I try to connect from my Windows machine, it gives the following error:

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.

Please find docker info output:

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

Can you please help me to resolve this?

2 Answers 2

11

You need to configure the Docker daemon in your ubuntu server in order for it to accept tcp connection. By default Docker listen on the unix socket /var/run/docker.sock. To configure your daemon, you can have a look at the documentation here

Step-by-step configuration (in this example, everything is done on the Ubuntu VM) :

Configure the daemon
On Ubuntu, by default you are using systemd. You need to edit the configuration file (usually located in /lib/systemd/system/docker.service) :

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

With this example, the Docker daemon no longer listen on the unix socket. It only listen on tcp call from localhost.
Restart the daemon :

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

Configure the client (still on the VM)
After restarting the daemon, your docker client does not work anymore (as you've just told the client to only listen to tcp connection). Thus, if you do docker image ls it should not respond. In order for your client to work, you need to tell it which server to connect to :

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

Now, your client should be able to connect to the daemon (i.e : docker image ls should print all the images)

This should work fine on your Ubuntu server. You just need to apply the same client configuration on Windows. If it does not work on Windows, then it means something else is blocking the trafic (probably a firewall).

Hope this helps.

19
  • Thanks Marc. It's a big document - let me read it and will update. If it is working, I will accept it as the answer.
    – SRaj
    May 17, 2019 at 12:39
  • Tried everything in the document, still no luck.
    – SRaj
    May 18, 2019 at 6:03
  • Can you be more specific ? I just edited the answer in order to add some configuration example. May 20, 2019 at 8:24
  • Thanks Marc for the detailed steps. I have already done the change. I am able to get the docker output if I connect to localhost, but I am unable to do so if I use the IP of the same VM machine (where docker CLI is running): controller@ubuntuserver:~$ docker -H 192.168.56.107:2375 ps Cannot connect to the Docker daemon at tcp://192.168.56.107:2375. Is the docker daemon running? controller@ubuntuserver:~$ docker -H localhost:2375 ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    – SRaj
    May 21, 2019 at 9:34
  • The truncated "ifconfig" output below: enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.56.107 netmask 255.255.255.0 broadcast 192.168.56.255 inet6 fe80::a00:27ff:fe70:dff2 prefixlen 64 scopeid 0x20<link>
    – SRaj
    May 21, 2019 at 9:38
0

Maybe your server ICMP protocol has been prohibited,check it by this cmd:

iptables -L INPUT --line-numbers

and if terminal shows:

result

and delete this record by cmd

iptables -D INPUT 7

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.