gpt4 book ai didi

linux - 使用 docker 和 --privileged 构建

转载 作者:IT王子 更新时间:2023-10-29 00:43:25 27 4
gpt4 key购买 nike

我正在使用 this guide使用 Amazon Lex 和 Raspberry Pi 构建语音套件,但我需要使用 Docker。问题是指南 curl 并运行的脚本需要访问/dev/tty。我可以在运行 docker 容器时授予对/dev/tty 的访问权限,但我不知道如何在构建容器时执行此操作。

我的 Dockerfile 如下所示:

FROM resin/rpi-raspbian

WORKDIR /app

ADD . /app

#The script requires these
RUN apt-get update
RUN apt-get install iputils-ping

#The script has to be run with sudo priviliges but not as root
USER root
ADD /sudoers.txt /etc/sudoers
RUN chmod 440 /etc/sudoers


RUN useradd -ms /bin/bash lex
RUN echo 'lex:test' | chpasswd

RUN curl https://get.pimoroni.com/phatdac | bash

USER lex

EXPOSE 80

#Comment the last RUN command and uncomment this
#CMD curl https://get.pimoroni.com/phatdac | bash

当我尝试构建容器时

docker build -t raspi1 .

它在脚本上崩溃,因为它无法访问/dev/tty。

运行容器时,我可以使用此脚本授予对/dev/tty 和/dev/snd 的访问权限

#!/bin/sh

docker run -ti --rm \
-v /dev/snd:/dev/snd \
--privileged \
raspi7

然后尝试在 Dockerfile 中通过 CMD 在启动时使用脚本。但是,如果我这样做,那么每次运行时我都需要使用该脚本,并且我还需要在脚本完成后对其他内容执行 RUN,这在构建时放在 Dockerfile 上会很好。

TLDR;构建docker镜像时如何给/dev/tty和/dev/snd赋权?

最佳答案

Docker 目前不支持公开设备,或者在构建时不支持特权操作。

根据@cpuguy83,您现在正在做的事情——在不访问主机的情况下构建一个可移植的图像,并在容器首次启动时完成配置——是正确的做法:

Doing this kind of stuff at first container start is exactly the right way to go. It's a runtime configuration it shouldn't be in the image.

参见 bountysource .

还有和旧但仍然开放的moby的问题。

关于linux - 使用 docker 和 --privileged 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48098671/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com