Setting up a development environment is not easy if you are inexperienced, especially if a lot of technologies you wish to learn are involved.
This tutorial aims to show you how to set up a basic Docker-based Python development environment with CUDA support in PyCharm or Visual Studio Code.
For this tutorial I’m using a toy project with just 3 files:
Dockerfile
to generate the container.requirements.txt
file that contains the dependencies of the project.single run.py
file that contains some code to run. Obviously your personal project will most likely be more complex, you may use a different method for dependency management and you might also use a docker-compose.yaml
file but for the sake of getting my point through that is pointless complexity.For an article more focused on Docker and Dockerfiles I recommend the Docker Beginner’s Guide.
Here follow our Dockerfile and a brief explanation
FROM nvidia/cuda:10.2-devel ## Miniconda install copy-pasted from Miniconda's own Dockerfile reachable ## at: https://github.com/ContinuumIO/docker-images/blob/master/miniconda3/debian/Dockerfile ENV PATH /opt/conda/bin:$PATH RUN apt-get update --fix-missing && \ apt-get install -y wget bzip2 ca-certificates libglib2.0-0 libxext6 libsm6 libxrender1 git mercurial subversion && \ apt-get clean RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \ /bin/bash ~/miniconda.sh -b -p /opt/conda && \ rm ~/miniconda.sh && \ /opt/conda/bin/conda clean -tipsy && \ ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \ echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \ echo "conda activate base" >> ~/.bashrc && \ find /opt/conda/ -follow -type f -name '*.a' -delete && \ find /opt/conda/ -follow -type f -name '*.js.map' -delete && \ /opt/conda/bin/conda clean -afy ## Project setup WORKDIR /code COPY requirements.txt . RUN pip install -r requirements.txt COPY . . CMD ["python", "./run.py"]
#docker #cuda #python #visual-studio-code #pycharm