使用docker和--privileged构建

问题描述 投票:3回答:1

我正在使用this guide与Amazon Lex和Raspberry Pi构建语音工具包,但我需要使用Docker。问题是指南卷曲和运行的脚本需要访问/ 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授予权限?

linux amazon-web-services docker dockerfile amazon-lex
1个回答
0
投票

您的问题可能是您的docker镜像中不存在/ dev / snd。当您运行容器时,实际上是将主机OS / dev / snd挂载到容器中,以便运行脚本。看看以下内容:

[INSERT] > cat Dockerfile
FROM resin/rpi-raspbian

RUN ls /dev && ls /dev/tty && ls /dev/snd


[INSERT] > docker build .
Sending build context to Docker daemon  39.94kB
Step 1/2 : FROM resin/rpi-raspbian
 ---> d008ca006edc
Step 2/2 : RUN ls /dev && ls /dev/tty && ls /dev/snd
 ---> Running in 0b738007c71c
core
fd
full
mqueue
null
ptmx
pts
random
shm
stderr
stdin
stdout
tty
urandom
zero
/dev/tty
/bin/ls: cannot access /dev/snd: No such file or directory
The command '/bin/sh -c ls /dev && ls /dev/tty && ls /dev/snd' returned a non-zero code: 2

如您所见,/ dev / tty存在,您可以访问它。 / dev / snd不存在,并且您不在正在运行的容器中,因此您无法将其作为卷(在运行容器时正在执行)进行安装。我建议尝试更全面地了解您正在运行的脚本正在做什么,评估它是否需要访问主机的/ dev / snd,如果是这样,您可能只在运行容器内运行脚本,因为图像不有任何主机概念。

© www.soinside.com 2019 - 2024. All rights reserved.