Skip to content

Instantly share code, notes, and snippets.

@Vyasdev217
Last active June 22, 2023 09:32
Show Gist options
  • Save Vyasdev217/f19f23d3aa20876dc3a01bacea1ce7c7 to your computer and use it in GitHub Desktop.
Save Vyasdev217/f19f23d3aa20876dc3a01bacea1ce7c7 to your computer and use it in GitHub Desktop.
An example to setup a docker container and jupyter server in a server and access from another host in LAN
### An example to setup a docker container and jupyter server in a server and access from another host in LAN
## Pull docker image [Only first time]
sudo docker pull tensorflow/tensorflow:latest-gpu-jupyter
## Create and start docker container
sudo docker run --gpus all -it -p 192.168.x.x:8889:8888 -v /source/derectory/in/host:/dest/directory/in/container tensorflow/tensorflow:latest-gpu-jupyter bash
# Create and start docker container with current directory as source directory in host
sudo docker run --gpus all -it -p 192.168.x.x:8889:8888 -v ./:/fromhost tensorflow/tensorflow:latest-gpu-jupyter bash
# Command split:
#
# --gpus all
# To use all available gpus
#
# -it
# allocate a pseudo-TTY (terminal) and keep the container attached to your current terminal session
# It allows you to interact with the container's shell or command-line interface
#
# -p 192.168.x.x:8889:8888
# Forward server from localhost:8888 in container to 192.168.x.x:8889 in LAN
#
# -v /source/derectory/in/host:/dest/directory/in/container
# Syncronize '/source/derectory/in/host' in host with '/dest/directory/in/container' in container
#
# tensorflow/tensorflow:latest-gpu-jupyter
# Name of docker image to be used
#
# bash
# No need to explain
## Start jupyter server
jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root
## Fetch jupyter server url
http://192.168.30.151:8889/?token=<token-can-be-found-in-terminal-after-starting-server>
## Detach from container terminal without killing it
^P^Q<Enter>
#Ctrl+P Ctrl+Q ENTER
## Attach to a container
docker attach container_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment