Saturday, September 26, 2020

Connect Docker Client to Remote Docker Host

This article will help to connect a Docker client to a remote Docker host Server.


Prerequisites:

Docker Server is installed on remote Docker host server 

Docker Client is installed on the client machine.

Docker Client must have ssh connectivity with the remote server


To Setup the ssh key

On Docker Client 

$ ssh-keygen

$ cat /<<user>>/.ssh/id_rsa.pub

copy these contents and got to remote server

On Docker Remote Server

append the content of client's ssh key to /<<user>>/.ssh/authorizedkeys

On Docker Client 

export DOCKER_HOST=ssh://<<user>>@<<RemoteIP>>

Now your client is connected to Remote Host Machine.

if you run docker commands it will connect to Remote Docker server.


How to disconnect to Remote server

$  unset DOCKER_HOST




4 comments:

Unknown said...

Not able to connect docker server from Docker client machine. Please suggest.

Server - 172.31.28.37 (private) 3.93.73.204 (Public)
Client - 172.31.24.217 (Private) 34.224.156.201 (Public)

ubuntu@ip-172-31-24-217:~/.ssh$ export DOCKER_HOST=ssh://ubuntu@172.31.28.37
ubuntu@ip-172-31-24-217:~/.ssh$ docker --version

Command 'docker' not found, but can be installed with:

sudo snap install docker # version 19.03.11, or
sudo apt install docker.io

See 'snap info docker' for additional versions.

------ Checking Connection ----------
ubuntu@ip-172-31-24-217:~/.ssh$ ssh ubuntu@172.31.28.37
Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 5.3.0-1035-aws x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

System information as of Tue Sep 29 19:35:51 UTC 2020

System load: 0.0 Processes: 94
Usage of /: 21.2% of 7.69GB Users logged in: 1
Memory usage: 20% IP address for eth0: 172.31.28.37
Swap usage: 0%


36 packages can be updated.
31 updates are security updates.

New release '20.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


Last login: Tue Sep 29 19:27:15 2020 from 34.224.156.201
ubuntu@ip-172-31-28-37:~$

Raman said...

First you need to install docker on client system

Jersey Shore Technology said...

Secure Speech Recognition kiosk CenterThank you so much uploading this post.it is very helpful to us. Great work!

DevOps Enabler & Co. said...

wonderful post. this is very well written and unique. Thank you for sharing this post here. keep sharing this in future. Managed Devops Solutions

Post a Comment