Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save prateekrajgautam/f4ee88c4731e529463088bc975dd7fb3 to your computer and use it in GitHub Desktop.
Save prateekrajgautam/f4ee88c4731e529463088bc975dd7fb3 to your computer and use it in GitHub Desktop.
Steps to connect to docker server using tailscale

You need a bash terminal of linu or windown users need to install git bash

after installation rightclick and select git bash here Now you have bash on windows

ssh in to server with

# define server IP
IP=10.135.27.6 
# define USERNAME
USERNAME=CHANGEME
ssh -X $USERNAME@$IP

enter your password when asked now you are inside server now create docker container with following commands

# define USERNAME
USERNAME=CHANGEME

docker run -it --name myjupyter_$USER --volume /home/$USERNAME/volumes/jupyterdata:/app ubuntu:latest

This will take some time and takes you in to docker container, update and execute in side docker

apt update -y
apt install sudo curl vim openssh-server python python3 python3-pip -y
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
vim /etc/ssh/sshd_config
# it will open file in your terminal, use arrow keys to brows to a line #Port, and #listeing address... 0.0.0.0 un comment by removing # before
# to edit in vim press `a` to enter in to editing mode after editing press `esc` to excape and then press `:wq` to exit saving change
service ssh start
you might need to allow firewall rules search for command `ufw`

create user account for ssh access

SSHUSERNAME=<changeme>
SSHPASSWORD=<changeme>
adduser --disabled-password --gecos "" $SSHUSERNAME
echo "$SSHUSERNAME:$SSHPASSWORD" | chpasswd
usermod -aG sudo $SSHUSERNAME

Install tailscale for networking

Now we will install tailscale on our local system and docker container with command once on local system and then on remoter container you need to create and account on tailscale using google account

1 Install tailscale on local system

curl -fsSL https://tailscale.com/install.sh | sh
tailscale up 
tailscale login

It will give you a url to login copy it and open it in your browser to connect device

Now you can check the tailscale ip of your device

tailscale status

2 Install tailscale on docker container

curl -fsSL https://tailscale.com/install.sh | sh
# https://tailscale.com/kb/1112/userspace-networking
tailscaled --tun=userspace-networking --socks5-server=localhost:1055 --outbound-http-proxy-listen=localhost:1055 &
tailscale up 
tailscale login

Tt will give you a url to login copy it and open it in your browser to connect device

now you can check the tailscale ip of your container

tailscale status

At this point you have a docker container running sshserver, you have ssh login for this container, and you have installed tailscale on local as well as on docker conteiner.

so you can ssh into you docker container using IP of container say ContainerIP check with tailscale status

ssh -X SSHUSERNAME@<ContainerIP>
# enter SSHPASSWORD when it ask

try ssh tunnel to browse website running in container on port 80 lets say you want to use it for web browser

ssh with tunnel on port 80

ssh -X -L 80:127.0.0.1:80 SSHUSERNAME@<ContainerIP>
# enter SSHPASSWORD when it ask
python3 -m http.server 80
# it will start python server and give you a link, click on it and you can view files in directory as website on your browser
# 

ssh with tunnel on port 8888, commonly used with jypyterlab

ssh -X -L 8888:127.0.0.1:88888 SSHUSERNAME@<ContainerIP>
# enter SSHPASSWORD when it ask
# this time we will install jupyterlab and then execute it 
pip3 install jupyterlab
jupyter-lab
# it will start jupyterlab server and give you a link, click on it and you can view use jupyter on your localhost:8888

Now you can train your machine learing algorithms

  • to detach from docker container terminal press ctrl+q+p
  • to reattach to docker container docker attach containerid
  • in the docker we have a directory /app mapped on our server, so even if contain is lost (as it will be your data and models saved in the app folder are present on the mapped directory on the server under your username)
  • you may want to use key based autologin search for ssh-keygen and public and private key generation

References

Known issue:

  • server is running outdated version of docker so updated images will not work properly, therefore use ubuntu:18.04 docker run ubuntu:18.04
  • some things will work with this but latest software will not work as it is image from year 2018
  • for mechatronics and mta students who need to run solidworks and other GUI based simulation softwares server access they can use vagrant and virtualbox to install windows and install your software as needed. You can search internet for instructions, I will try to write tutorial some other time.
  • lastly I would suggest you to try nix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment