Docker Quickstart Guide for Ultralytics
This guide serves as a comprehensive introduction to setting up a Docker environment for your Ultralytics projects. Docker is a platform for developing, shipping, and running applications in containers. It is particularly beneficial for ensuring that the software will always run the same, regardless of where it's deployed. For more details, visit the Ultralytics Docker repository on Docker Hub.
What You Will Learn
- Setting up Docker with NVIDIA support
- Installing Ultralytics Docker images
- Running Ultralytics in a Docker container
- Mounting local directories into the container
- Make sure Docker is installed on your system. If not, you can download and install it from Docker's website.
- Ensure that your system has an NVIDIA GPU and NVIDIA drivers are installed.
Setting up Docker with NVIDIA Support
First, verify that the NVIDIA drivers are properly installed by running:
Installing NVIDIA Docker Runtime
Now, let's install the NVIDIA Docker runtime to enable GPU support in Docker containers:
# Add NVIDIA package repositories curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - distribution=$(lsb_release -cs) curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list # Install NVIDIA Docker runtime sudo apt-get update sudo apt-get install -y nvidia-docker2 # Restart Docker service to apply changes sudo systemctl restart docker
Verify NVIDIA Runtime with Docker
docker info | grep -i runtime to ensure that
nvidia appears in the list of runtimes:
Installing Ultralytics Docker Images
Ultralytics offers several Docker images optimized for various platforms and use-cases:
- Dockerfile: GPU image, ideal for training.
- Dockerfile-arm64: For ARM64 architecture, suitable for devices like Raspberry Pi.
- Dockerfile-cpu: CPU-only version for inference and non-GPU environments.
- Dockerfile-jetson: Optimized for NVIDIA Jetson devices.
- Dockerfile-python: Minimal Python environment for lightweight applications.
- Dockerfile-conda: Includes Miniconda3 and Ultralytics package installed via Conda.
To pull the latest image:
Running Ultralytics in Docker Container
Here's how to execute the Ultralytics Docker container:
-it flag assigns a pseudo-TTY and keeps stdin open, allowing you to interact with the container. The
--ipc=host flag enables sharing of host's IPC namespace, essential for sharing memory between processes. The
--gpus flag allows the container to access the host's GPUs.
Note on File Accessibility
To work with files on your local machine within the container, you can use Docker volumes:
/path/on/host with the directory path on your local machine and
/path/in/container with the desired path inside the Docker container.
Congratulations! You're now set up to use Ultralytics with Docker and ready to take advantage of its powerful capabilities. For alternate installation methods, feel free to explore the Ultralytics quickstart documentation.
Created 2023-11-12, Updated 2023-11-16
Authors: glenn-jocher (2)