我在用着本指南 https://aws.amazon.com/blogs/ai/build-a-voice-kit-with-amazon-lex-and-a-raspberry-pi/使用 Amazon Lex 和 Raspberry Pi 构建语音套件,但我需要使用 Docker。
问题是指南卷曲并运行的脚本需要访问 /dev/tty。我可以授予对 /dev/tty 的访问权限runningdocker 容器,但我不知道在构建容器时如何做到这一点。
我的 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 上会很好。
太长了;
构建docker镜像时如何给/dev/tty和/dev/snd授予权限?
Docker 目前不支持公开设备,也不支持构建时的特权操作。
根据@cpuguy83,您现在正在做的事情 - 构建一个可移植的映像,无需访问主机并在容器首次启动时完成配置 - 是正确的做法:
在第一次容器启动时做这种事情正是正确的方法。
这是一个运行时配置,不应该出现在图像中。
See 赏金来源 https://www.bountysource.com/issues/964893-docker-build-should-support-privileged-operations.
也有,比较老但是还开着moby https://github.com/moby/moby/issues/1916的问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)