Skip to content
/ PyDocker Public template

A simple Python Docker workspace template for developing Python projects using uv as package manager within Docker containers supported GPU usage.

License

Notifications You must be signed in to change notification settings

liuyuweitarek/PyDocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyDocker

A simple Python Docker workspace template for developing Python projects within Docker containers.

You could use this template to start/containerize a development environment for your Python project.

Usage

  1. Congfigure

    docker-compose.yml

    build:
      context: .
      dockerfile: Dockerfile
      args:
        PROJECT_NAME: "my-project" # Name you project and  init for you
        UBUNTU_VERSION: "22.04"    # Choose ubuntu version
        PYTHON_VERSION: "3.10"     # Choose python version
    develop:
      watch:
        - action: sync
          path: ./my-project       # Don't forget to modify the default folder name to your project name here!
  2. Start the development environment:

    $ docker compose up -d 

    Now you will find that your {PROJECT_NAME} folder appears in the current directory and the container is running.

    From,

    .
    ├── ...
    ├── Dockerfile
    ├── docker-compose.yml
    

    to,

    .
    ├── ...
    ├── {PROJECT_NAME}
        # See more details in https://docs.astral.sh/uv/concepts/projects/init/#applications.
        ├── (Default uv project structure)
    ├── Dockerfile
    ├── docker-compose.yml
    
  3. Access docker container terminal with:

    $ docker exec -it dev /bin/bash

    Exit terminal with CTRL + D.

  4. Stop docker container with:

    $ docker compose down
  5. Add packages

    e.g. Install cuda available torch:

    $ uv lock --index https://download.pytorch.org/whl/cu118
    $ uv add numpy==1.26.4  torch==2.1.2

    P.S. Torch-CUDA-PYTHON compatible version table

Q&A

  1. How to use GPU in container?

    For gpu usage, ensure your system meets the following requirements:

    1. Windows users need to enable WSL

      To run Docker with GPU support on Windows, you must enable Windows Subsystem for Linux (WSL).

      Follow the instructions here: Setting up WSL.

    2. Install Docker

      Windows users: Download and install Docker Desktop.

      Linux users: Install Docker Engine following the instructions here.

    3. Install CUDA Toolkit

      Ensure that your system has the CUDA Toolkit installed, which is necessary for GPU acceleration.

      Refer to the guide: Installing CUDA Toolkit.

    4. Install NVIDIA Container Toolkit

      This is required to enable Docker containers to use the GPU.

      Follow the instructions to install the NVIDIA Container Toolkit here.

    5 Test your gpu util with test_gpu_util.py.

  2. Do I need to reinstall packages in the container once it closed?

    No need. The packages you intalled in the container will still be remained. All packages will be kept in the {your-project-name}/.venv which will be mounted to the container.

About

A simple Python Docker workspace template for developing Python projects using uv as package manager within Docker containers supported GPU usage.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published