我正在使用这个指南来使用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的权限?
命令是无用的,因为默认情况下你就是root用户,除非你使用了
USER xxx`命令。 - user2915097