{"id":14978992,"url":"https://github.com/anibali/docker-pytorch","last_synced_at":"2025-05-16T13:04:40.141Z","repository":{"id":41526916,"uuid":"91998524","full_name":"anibali/docker-pytorch","owner":"anibali","description":"A Docker image for PyTorch","archived":false,"fork":false,"pushed_at":"2023-08-22T06:54:38.000Z","size":92,"stargazers_count":982,"open_issues_count":0,"forks_count":225,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-02T06:32:13.394Z","etag":null,"topics":["cuda","docker","docker-image","pytorch"],"latest_commit_sha":null,"homepage":null,"language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anibali.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-05-22T01:11:02.000Z","updated_at":"2025-03-24T21:24:18.000Z","dependencies_parsed_at":"2023-10-20T17:27:51.635Z","dependency_job_id":null,"html_url":"https://github.com/anibali/docker-pytorch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anibali%2Fdocker-pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anibali%2Fdocker-pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anibali%2Fdocker-pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anibali%2Fdocker-pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anibali","download_url":"https://codeload.github.com/anibali/docker-pytorch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999859,"owners_count":21031046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cuda","docker","docker-image","pytorch"],"created_at":"2024-09-24T13:58:52.298Z","updated_at":"2025-04-09T08:05:22.298Z","avatar_url":"https://github.com/anibali.png","language":"Dockerfile","readme":"# PyTorch Docker image\n\n[![Docker image version](https://img.shields.io/docker/image-size/anibali/pytorch/latest)](https://hub.docker.com/r/anibali/pytorch/)\n[![Docker image pulls](https://img.shields.io/docker/pulls/anibali/pytorch)](https://hub.docker.com/r/anibali/pytorch/)\n[![Docker image size](https://img.shields.io/docker/v/anibali/pytorch/latest)](https://hub.docker.com/r/anibali/pytorch/)\n\nUbuntu + PyTorch + CUDA (optional)\n\n\n## Requirements\n\nIn order to use this image you must have Docker Engine installed. Instructions\nfor setting up Docker Engine are\n[available on the Docker website](https://docs.docker.com/engine/installation/).\n\n### CUDA requirements\n\nIf you have a CUDA-compatible NVIDIA graphics card, you can use a CUDA-enabled\nversion of the PyTorch image to enable hardware acceleration. I have only\ntested this in Ubuntu Linux.\n\nFirstly, ensure that you install the appropriate NVIDIA drivers. On Ubuntu,\nI've found that the easiest way of ensuring that you have the right version\nof the drivers set up is by installing a version of CUDA _at least as new as\nthe image you intend to use_ via\n[the official NVIDIA CUDA download page](https://developer.nvidia.com/cuda-downloads).\nAs an example, if you intend on using the `cuda-10.1` image then setting up\nCUDA 10.1 or CUDA 10.2 should ensure that you have the correct graphics drivers.\n\nYou will also need to install the NVIDIA Container Toolkit to enable GPU device\naccess within Docker containers. This can be found at\n[NVIDIA/nvidia-docker](https://github.com/NVIDIA/nvidia-docker).\n\n\n## Prebuilt images\n\nPrebuilt images are available on Docker Hub under the name\n[anibali/pytorch](https://hub.docker.com/r/anibali/pytorch/).\n\nFor example, you can pull an image with PyTorch 2.0.1 and CUDA 11.8 using:\n\n```bash\n$ docker pull anibali/pytorch:2.0.1-cuda11.8\n```\n\n\n## Usage\n\n### Running PyTorch scripts\n\nIt is possible to run PyTorch programs inside a container using the\n`python3` command. For example, if you are within a directory containing\nsome PyTorch project with entrypoint `main.py`, you could run it with\nthe following command:\n\n```sh\ndocker run --rm -it --init \\\n  --gpus=all \\\n  --ipc=host \\\n  --user=\"$(id -u):$(id -g)\" \\\n  --volume=\"$PWD:/app\" \\\n  anibali/pytorch python3 main.py\n```\n\nHere's a description of the Docker command-line options shown above:\n\n* `--gpus=all`: Required if using CUDA, optional otherwise. Passes the\n  graphics cards from the host to the container. You can also more precisely\n  control which graphics cards are exposed using this option (see documentation\n  at https://github.com/NVIDIA/nvidia-docker).\n* `--ipc=host`: Required if using multiprocessing, as explained at\n  https://github.com/pytorch/pytorch#docker-image.\n* `--user=\"$(id -u):$(id -g)\"`: Sets the user inside the container to match your\n  user and group ID. Optional, but is useful for writing files with correct\n  ownership.\n* `--volume=\"$PWD:/app\"`: Mounts the current working directory into the container.\n  The default working directory inside the container is `/app`. Optional.\n\n### Running graphical applications\n\nIf you are running on a Linux host, you can get code running inside the Docker\ncontainer to display graphics using the host X server (this allows you to use\nOpenCV's imshow, for example). Here we describe a quick-and-dirty (but INSECURE)\nway of doing this. For a more comprehensive guide on GUIs and Docker check out\nhttp://wiki.ros.org/docker/Tutorials/GUI.\n\nOn the host run:\n\n```sh\nsudo xhost +local:root\n```\n\nYou can revoke these access permissions later with `sudo xhost -local:root`.\nNow when you run a container make sure you add the options `-e \"DISPLAY\"` and\n`--volume=\"/tmp/.X11-unix:/tmp/.X11-unix:rw\"`. This will provide the container\nwith your X11 socket for communication and your display ID. Here's an\nexample:\n\n```sh\ndocker run --rm -it --init \\\n  --gpus=all \\\n  -e \"DISPLAY\" --volume=\"/tmp/.X11-unix:/tmp/.X11-unix:rw\" \\\n  anibali/pytorch python3 -c \"import tkinter; tkinter.Tk().mainloop()\"\n```\n\n### Deriving your own images\n\nThe recommended way of adding additional dependencies to an image is to create\nyour own Dockerfile using one of the PyTorch images from this project as a base.\n\nFor example, let's say that you require OpenCV and wish to work with PyTorch\n2.0.1. You can create your own Dockerfile using\n`anibali/pytorch:2.0.1-cuda11.8-ubuntu22.04` as the base image and install\nOpenCV using additional build steps:\n\n```dockerfile\nFROM anibali/pytorch:2.0.1-cuda11.8-ubuntu22.04\n\n# Set up time zone.\nENV TZ=UTC\nRUN sudo ln -snf /usr/share/zoneinfo/$TZ /etc/localtime\n\n# Install system libraries required by OpenCV.\nRUN sudo apt-get update \\\n \u0026\u0026 sudo apt-get install -y libgl1-mesa-glx libgtk2.0-0 libsm6 libxext6 \\\n \u0026\u0026 sudo rm -rf /var/lib/apt/lists/*\n\n# Install OpenCV from PyPI.\nRUN pip install opencv-python==4.5.1.48\n```\n\n\n## Development and contributing\n\nThe Dockerfiles in the `dockerfiles/` directory are automatically generated by\nthe `manager.py` script using details in `images.yml` and the templates in\n`templates/`.\n\nHere's an example workflow illustrating how to create a new Dockerfile.\n\n1. (Optional) Create a new template file in `templates/` if none of the existing\n   ones are appropriate.\n2. Create a new entry in `images.yml` (see the existing entries for examples).\n3. Generate the Dockerfile by running `python manager.py`. A new directory\n   containing the Dockerfile will be created in `dockerfiles/`.\n4. Build the generated Dockerfile and test that it works. You can stop here if\n   you are creating an image for your own use.\n5. (Optional) Submit a PR if you think that your new image might be useful for\n   others, and it will be considered for publication.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanibali%2Fdocker-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanibali%2Fdocker-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanibali%2Fdocker-pytorch/lists"}