Basic docker project template for Machine Learning.
Supported: GPU (CUDA), pytorch, mount binds, volumes, host user, Jupyter, pip cache mounting, CUDA version from environment, freezed code for experiments and live code for Jupyter.
Suggested project structure:
configsfor any configuration files (.yaml,.json, etc.);figuresfor images, tables and other easy accessable files;libfor code;notebooksfor jupyter notebooks;requirementsfor pip-syntaxed requirements,common.txtfor any andtorch+X.txtfor CUDA-dependent;runfor docker bash scripts, configure permissions to execute files inside:chmod +x run/*;.for project service files.
Define environmental variables:
USER_IDandGROUP_ID, equal to your userid -uandid -grespectively;DEVICEgpu you want to use (0);CPUSETcpu range you want to use (0-15);JUPYTER_PORTport to expose for a jupyter server (8000);BASE_IMAGEtag of CUDA base image from docker hub fitting your CUDA driver (nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04);TORCH_CUDAtorch cuda version, suffix in torch requirements (cu102,cu111,cu113, or add your own);PYTHON_VERSIONversion of python you want to install inside the container (3.9).
You may store these variables in .env file in your project root along with any secrets and tokens
that your project needs. Just make sure it is not tracked by git.
Dependencies can be configured in docker-compose.yml.
Once done:
# to build docker image
docker compose build cherry
# to start jupyter server
run/jupyter
# to run an experiment
run/test
If you have problems with internet connection inside containers (can be on Fedora)
use docker run instead of docker compose run:
# to start jupyter server
run/docker jupyter
# inside container (docker@X: /cherry$)
jupyter notebook --no-browser --ip 0.0.0.0 --port 8000
# Ctrl+P, Ctrl+Q to detach