如何在docker-compose中配置--device-cgroup-rule参数?是否支持?
Does docker-compose support the
--device-cgroup-rule option? Great question! Yes, docker-compose does support configuring the equivalent of the --device-cgroup-rule flag you use with docker run—it just uses a key that’s a bit easy to overlook in the official docs.
Here’s how to set it up:
Suppose your working docker run command looks like this:
docker run --device-cgroup-rule='c 189:* rmw' my-image
You can replicate this in your docker-compose.yml by adding the devices_cgroup_rules field under your service definition, like so:
version: '3.8' services: my-service: image: my-image devices_cgroup_rules: - 'c 189:* rmw'
A quick note on the rule format:
Each rule follows the structure [device-type] [major]:[minor] [permissions], where:
device-typeis eitherc(for character devices) orb(for block devices)majorandminorare device numbers—use*to match all devices of that typepermissionscan be any combination ofr(read),w(write), andm(mknod)
If you need multiple device cgroup rules, just add additional entries to the devices_cgroup_rules list.
内容的提问来源于stack exchange,提问作者Petr
相关产品推荐
相关产品推荐

