【问题标题】:I created a folder in the dockerfile but can’t access it?我在 dockerfile 中创建了一个文件夹但无法访问它?
【发布时间】:2021-07-15 05:24:36
【问题描述】:

ubuntu中没有/dev/net目录;我想创建一个tun设备。

这是我的 dockerfile:

FROM ubuntu

RUN apt-get update && apt-get -y install net-tools iptables iproute2
RUN mkdir -p /dev/net/
RUN cd /dev/net/
RUN ["mknod", "/dev/net/tun", "c","10","200"]

这是错误信息:

PS C:\Users\Penn\AndroidStudioProjects\TunVpn\server> docker build -t tunvpn:v1 .
[+] Building 1.9s (7/9)
 => [internal] load build definition from Dockerfile                                                                                       0.1s
 => => transferring dockerfile: 370B                                                                                                       0.0s
 => [internal] load .dockerignore                                                                                                          0.1s
 => => transferring context: 2B                                                                                                            0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                           1.3s
 => [1/6] FROM docker.io/library/ubuntu@sha256:3c9c713e0979e9bd6061ed52ac1e9e1f246c9495aa063619d9d695fb8039aa1f                            0.0s
 => CACHED [2/6] RUN apt-get update && apt-get -y install net-tools iptables iproute2                                                      0.0s
 => CACHED [3/6] RUN mkdir -p /dev/net/                                                                                                    0.0s
 => ERROR [4/6] RUN cd /dev/net/                                                                                                           0.4s
------
 > [4/6] RUN cd /dev/net/:
#7 0.348 /bin/sh: 1: cd: can't cd to /dev/net/
------
executor failed running [/bin/sh -c cd /dev/net/]: exit code: 2

我想在/dev/net目录下创建一个tun文件

【问题讨论】:

  • 您是否打算将运行目录设为/dev/net?您可以尝试使用WORKDIR,将RUN cd /dev/net/ 替换为WORKDIR /dev/net/。如果它不起作用,请告诉我

标签: dockerfile


【解决方案1】:

由于 sudo 权限而出错。如果您想了解 sudo 在 docker Sudo inside docker987654321@

中的工作方式的详细信息,我希望这也有效
FROM ubuntu

RUN apt-get update && apt-get -y install net-tools iptables iproute2

#This is needed to avoid prompts

ENV DEBIAN_FRONTEND=noninteractive

# First add user as sudo in case issue in creating directory

RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo

CMD ["mkdir", "-p","/dev/net/"]

RUN cd /dev/net/
RUN ["mknod", "/dev/net/tun", "c","10","200"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-17
    • 2018-08-21
    • 1970-01-01
    • 2020-08-23
    • 2023-03-04
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多