Docker
What is docker?
- A standardized operation-system-level virtualization program.
- It creates “container” similar to virual machine but more flexible and light-weight.
- The container provides an isolated environment for programs to run, without messing up your own computers.
- More documentation are here
How to use a docker container?
- Get a docker images or writing your own Dockerfile:
docker pull jr55662003/jupyterlab-dev
- Run a docker container from docker images (gist):
- -it: make the container interactive
- -p [host port]:[docker port]
- bash –> command you want the container to execute
docker run -it --name="Container Name" -v /dir/in/host:/dir/in/docker -p 8888:8888 jr55662003/jupyterlab-dev bash
Connect to Jupyter lab in remote docker
-
Assume the docker container is running on remote server
- Open jupyter lab in remote docker:
ssh 127.0.0.1 # your server IP docker attach "Container Name" jupyter lab --allow-root --ip=0.0.0.0 # Copy the printed token in localhost:token="..."
- In local:
ssh -N -f -L [local port]:localhost:[docker exposed port] 127.0.0.1 # Open browser and enter url: localhost:[local port] # Login with the token or set new password
Disconnect the remote docker:
- To close single ssh:
# List all ssh processes ps aux | grep ssh kill [pid]
- To close all ssh:
pkill -f "ssh -N -f -L"
- Or you can write into a bash script like:
#!/bin/bash
PID=$(pgrep -f "ssh -N -f -L")
# Check if $PID is empty
if [ -z "$PID" ]
then
echo "No process need to kill."
exit 1
fi
echo "Killing $(pgrep -f "ssh -N -f -L")"
pkill -f "ssh -N -f -L"