Banner image

Motivation

  • Currently on Ubuntu 22.04 where Python 3.10 is default
  • For my Computer Vision assignment, torch==1.8.1 and torchvision==0.9.1 are required which are available with older versions of python
  • Installing older versions of python and managing pip was a mess!
  • I timeshifted back to a week ago and coded up the below Dockerfile

Steps

  1. Install Docker
  2. mkdir ~/Pydockerfiles && cd ~/Pydockerfiles
  3. touch Dockerfile
  4. touch run
  5. touch requirements.txt
  6. Populate requirements.txt if you have any reference list
  7. chmod +x run
  8. Populate the two created files (code given below)
  9. ./run
  10. The notebook server link should open in the browser if all went well

Dockerfile

FROM python:3.8-slim-buster

WORKDIR /home

COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install jupyter notebook
RUN apt-get update && apt-get install -y python3-opencv

CMD jupyter notebook --ip 0.0.0.0 --no-browser --allow-root

run

#!/bin/sh

docker build --tag python-docker .

docker run -it \
      --rm \
      -p 8888:8888 \
      --name py-doc \
      -v ~/{WORK_DIRECTORY_PATH}:/home/{WORK_DIRECTORY_NAME} \
      python-docker

References