You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-p 8888:8888: Port forward to use Jupyer Lab from your host browser
-v $(pwd):/workspace: Map the host's current folder to the one /workspace inside the container to sync files
--shm-size: Increase shared memory size from 64MB
$ docker run -d --gpus all -it -u root -p 8888:8888 -v $(pwd):/workspace --shm-size=256m tensorflow/tensorflow:latest-gpu
Find out the container ID (49ad4f2852c7 is the ID here)
$ dockerp ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f95b6ac4e565 tensorflow/tensorflow:latest-gpu "/bin/bash" 4 seconds ago Up 2 seconds 0.0.0.0:8888->8888/tcp competent_robinson
Access to bash in the container
$ docker exec -it -u root CONTAINER_ID bash
________ _______________
___ __/__________________________________ ____/__ /________ __
__ / _ _ \_ __ \_ ___/ __ \_ ___/_ /_ __ /_ __ \_ | /| / /
_ / / __/ / / /(__ )/ /_/ / / _ __/ _ / / /_/ /_ |/ |/ /
/_/ \___//_/ /_//____/ \____//_/ /_/ /_/ \____/____/|__/
WARNING: You are running this container as root, which can cause new files in
mounted volumes to be created as the root user on your host machine.
To avoid this, run the container by specifying your user's userid:
$ docker run -u $(id -u):$(id -g) args...
root@f95b6ac4e565:/#
$ docker exec -it -u $(id -u):$(id -g) CONTAINER_ID bash
________ _______________
___ __/__________________________________ ____/__ /________ __
__ / _ _ \_ __ \_ ___/ __ \_ ___/_ /_ __ /_ __ \_ | /| / /
_ / / __/ / / /(__ )/ /_/ / / _ __/ _ / / /_/ /_ |/ |/ /
/_/ \___//_/ /_//____/ \____//_/ /_/ /_/ \____/____/|__/
You are running this container as user with ID 1000 and group 1000,
which should map to the ID and group for your user on the Docker host. Great!
tf-docker / >
Add /.local/bin to PATH
tf-docker / > export PATH=/.local/bin:$PATH
Set a password for Jupyter Lab
tf-docker / > jupyter notebook password
Enter password:
Verify password:
[NotebookPasswordApp] Wrote hashed password to /.jupyter/jupyter_notebook_config.json
tf-docker / >
Start Jupyter Lab
tf-docker / > cd workspace
tf-docker /workspace > jupyter lab --no-browser --ip=*
/usr/local/lib/python3.6/dist-packages/IPython/paths.py:67: UserWarning: IPython parent '/' is not a writable location, using a temp directory.
" using a temp directory.".format(parent))
[W 05:55:57.761 LabApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 05:55:57.767 LabApp] JupyterLab extension loaded from /usr/local/lib/python3.6/dist-packages/jupyterlab
[I 05:55:57.767 LabApp] JupyterLab application directory is /usr/local/share/jupyter/lab
[I 05:55:57.768 LabApp] Serving notebooks from local directory: /workspace
[I 05:55:57.769 LabApp] The Jupyter Notebook is running at:
[I 05:55:57.769 LabApp] http://06982c99a734:8888/
[I 05:55:57.769 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Visit YOUR_UBUNTU_SERVER_IP:8888 and type the password
When you manage to login to Jupyer Lab and see the current folder, start a new notebook with Python 3 and execute the following scripts
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
You should get an output like
Num GPUs Available: 1
How to stop the container and restart from where you left
Steps to stop
Save your notebooks
Shutdown Jupyer Lab
Exit from Container's bash
Stop the container with $ docker stop CONTAINER_ID
⚠️ DO NOT delete the stopped container
If you did, don't worry. Start the step from the "Run a new container using the image" step
If you set up the workspace correctly, all your files should be available from your current folder to reproduce
Steps to resume
Start the container with $ docker start CONTAINER_ID
Login to bash
Start Jupyter Lab
When you need a pip package
Type the following commnad in Jupyter Notebook cell and run
-p 8888:8888: Port forward to use Jupyer Lab from your host browser
-v $(pwd):/workspace: Map the host's current folder to the one /workspace inside the container to sync files
--shm-size: Increase shared memory size from 64MB
$ docker run -d --gpus all -it -u root -p 8888:8888 -v $(pwd):/workspace --shm-size=256m pytorch/pytorch
Find out the container ID (f58be4bf9639 is the ID here)
$ dockerp ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f58be4bf9639 pytorch/pytorch "/bin/bash" 10 minutes ago Up 10 minutes 0.0.0.0:8888->8888/tcp beautiful_spence
$ docker exec -it -u $(id -u):$(id -g) CONTAINER_ID bash
groups: cannot find name for group ID 1000
I have no name!@f58be4bf9639:/workspace$
Add /.local/bin to PATH
I have no name!@f58be4bf9639:/workspace$ export PATH=/.local/bin:$PATH
Set a password for Jupyter Lab
I have no name!@f58be4bf9639:/workspace$ jupyter notebook password
Enter password:
Verify password:
[NotebookPasswordApp] Wrote hashed password to /.jupyter/jupyter_notebook_config.json
I have no name!@f58be4bf9639:/workspace$
Start Jupyter Lab
I have no name!@f58be4bf9639:/workspace$ jupyter lab --no-browser --ip=*
/opt/conda/lib/python3.7/site-packages/IPython/paths.py:67: UserWarning: IPython parent '/' is not a writable location, using a temp directory.
" using a temp directory.".format(parent))
[W 05:51:59.787 LabApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 05:51:59.793 LabApp] JupyterLab extension loaded from /opt/conda/lib/python3.7/site-packages/jupyterlab
[I 05:51:59.793 LabApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 05:51:59.795 LabApp] Serving notebooks from local directory: /workspace
[I 05:51:59.795 LabApp] The Jupyter Notebook is running at:
[I 05:51:59.795 LabApp] http://7686e1fe5a61:8888/
[I 05:51:59.795 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Visit YOUR_UBUNTU_SERVER_IP:8888 and type the password
When you manage to login to Jupyer Lab and see the current folder, start a new notebook with Python 3 and execute the following scripts
import torch
print(torch.cuda.is_available())
You should get an output like
True
How to stop the container and restart from where you left
Steps to stop
Save your notebooks
Shutdown Jupyer Lab
Exit from Container's bash
Stop the container with $ docker stop CONTAINER_ID
⚠️ DO NOT delete the stopped container
If you did, don't worry. Start the step from the "Run a new container using the image" step
If you set up the workspace correctly, all your files should be available from your current folder to reproduce
Steps to resume
Start the container with $ docker start CONTAINER_ID
Login to bash
Start Jupyter Lab
When you need a conda or pip package
Type the following command from Jupyter Notebook cell and run