Home Explore Blog CI



docker

7th chunk of `content/manuals/engine/containers/resource_constraints.md`
1cdf1264066da8fbf8d085fab9f35da98e0da5ff0e940b0a0000000100000a37
1000000-microsecond period, leaving at least 50000 microseconds available for
non-real-time tasks. To make this configuration permanent on systems which use
`systemd`, create a systemd unit file for the `docker` service. For example,
see the instruction on how to configure the daemon to use a proxy with a
[systemd unit file](../daemon/proxy.md#systemd-unit-file).

#### Configure individual containers

You can pass several flags to control a container's CPU priority when you
start the container using `docker run`. Consult your operating system's
documentation or the `ulimit` command for information on appropriate values.

| Option                     | Description                                                                                                                                                                               |
| :------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--cap-add=sys_nice`       | Grants the container the `CAP_SYS_NICE` capability, which allows the container to raise process `nice` values, set real-time scheduling policies, set CPU affinity, and other operations. |
| `--cpu-rt-runtime=<value>` | The maximum number of microseconds the container can run at real-time priority within the Docker daemon's real-time scheduler period. You also need the `--cap-add=sys_nice` flag.        |
| `--ulimit rtprio=<value>`  | The maximum real-time priority allowed for the container. You also need the `--cap-add=sys_nice` flag.                                                                                    |

The following example command sets each of these three flags on a `debian:jessie`
container.

```console
$ docker run -it \
    --cpu-rt-runtime=950000 \
    --ulimit rtprio=99 \
    --cap-add=sys_nice \
    debian:jessie
```

If the kernel or Docker daemon isn't configured correctly, an error occurs.

## GPU

### Access an NVIDIA GPU

#### Prerequisites

Visit the official [NVIDIA drivers page](https://www.nvidia.com/Download/index.aspx)
to download and install the proper drivers. Reboot your system once you have
done so.

Verify that your GPU is running and accessible.

#### Install nvidia-container-toolkit

Follow the official NVIDIA Container Toolkit [installation instructions](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).

#### Expose GPUs for use

Include the `--gpus` flag when you start a container to access GPU resources.

Title: Configuring Docker Containers for Real-Time Scheduling and NVIDIA GPU Access
Summary
This section details how to configure individual containers to use the real-time scheduler by setting flags such as `--cap-add=sys_nice`, `--cpu-rt-runtime`, and `--ulimit rtprio`. It provides an example command demonstrating how to set these flags on a container. Additionally, it explains how to access NVIDIA GPUs from within a Docker container, including prerequisites such as installing NVIDIA drivers and the NVIDIA Container Toolkit, followed by using the `--gpus` flag when starting the container.