Access Docker Host Remotely

Accessing docker remotely

Access Docker Host Remotely

In this blog, we will share you how to access docker host remotely using docker client.

REQUIREMENTS

  • Nano Server with Docker Installed
  • Client Machine to access the docker host through PowerShell

DOCKER ENGINE OVERVIEW

The docker engine is powered by dockerd in both windows and Linux. Dockerd is for Docker Daemon. This service has an ability to interface with docker client. It has lots of start-up options to customize the docker client service. We can configure the start-up option manually or we can setup in a configuration file. To configure the remote access to docker host, we need to specify the IP and port number using the customize options.

For more information about the dockerd, please check this URL: https://docs.docker.com/engine/reference/commandline/dockerd/#windows-configuration-file

CONFIGURING FIREWALL

  • We need to open a port a firewall on nano server (docker host). Execute the below command to open port 2375

netsh advfirewall firewall add rule name=”Docker Daemon” dir=in action=allow protocol=TCP localport=2375

Access Docker host Remotely

CREATING DAEMON FILE

  • Create a blank file named daemon.json under c:\programdata\docker\config folder using below command.

New-Item -Itemtype file c:\ProgramData\docker\config\daemon.json

Access Docker host Remotely
  • Add the host key into the file using the below command.

Add-Content ‘c:\ProgramData\docker\config\daemon.json’ ‘{ “hosts”: [“tcp://0.0.0.0:2375”, “npipe://”] }’

Access Docker host Remotely
  • To list the content from a file, use the below command.

Get-Content ‘C:\ProgramData\docker\config\daemon.json’

Access Docker host Remotely
  • Restart the Docker service using below command.

Restart-service docker

Access Docker host Remotely

INSTALLING DOCKER ENGINE IN CLIENT MACHINE

  • Execute the bunch of PowerShell scripts given below.

$package = “https://download.docker.com/components/engine/windows-server/cs-1.12/docker.zip”

Invoke-WebRequest $package -OutFile “$env:TEMP\docker.zip” -UseBasicParsing

Expand-Archive -Path “$env:TEMP\docker.zip” -DestinationPath $env:ProgramFiles

[Environment]::SetEnvironmentVariable(“path”,$env:Path + “;$($env:ProgramFiles)\Docker”, [EnvironmentVariableTarget]::Machine)

Above scripts will download the docker.zip and extract the files under program files folder. Also, it adds the environment variable for Docker folder.

Access Docker host Remotely
  • Now Docker folder will be available in C:\Program Files folder.
Access Docker host Remotely
  • Environment variable will also available for docker.
Access Docker host Remotely

ACCESS DOCKER HOST REMOTELY

  • Go to PowerShell and execute the below command to access the docker host remotely.

docker -H tcp://192.168.232.81:2375 version

The IP 192.168.232.81 belongs to nano server docker host. The version is a command to execute on the remote docker host server.

Access Docker host Remotely

Thanks for visiting this blog. We hope this blog is useful for you to learn how to access the docker host remotely through PowerShell.

Loges