【问题标题】:Dockerfile execution permission deniedDockerfile 执行权限被拒绝
【发布时间】:2020-06-02 17:46:19
【问题描述】:

我有这个 dockerfile

FROM alpine:3.8
ENV LANG C.UTF-8
RUN set -x && \
    apk add --no-cache \
              openrc \
              bash \
              libreswan \
              xl2tpd \
              ppp \
    && mkdir -p /var/run/pluto \
    && mkdir -p /var/run/xl2tpd \
    && touch /var/run/xl2tpd/l2tp-control
COPY ipsec.conf /etc/ipsec.conf
COPY ipsec.secrets /etc/ipsec.secrets
COPY xl2tpd.conf /etc/xl2tpd/xl2tpd.conf
COPY options.l2tpd.client /etc/ppp/options.l2tpd.client
COPY startup.sh /
RUN ["chmod", "+x", "/startup.sh"]

CMD ["./startup.sh"]

当我在本地运行它时,一切正常。但我正在尝试执行在 gcp vm (ubuntu) 中生成的图像,但出现以下错误

/bin/sh: can't open './startup.sh': Permission denied

有人可以帮我解决这个错误吗?

注意:我还尝试使用以下方法修改权限:

RUN ["chmod", "777", "/startup.sh"]
RUN chmod +x /startup.sh
RUN chmod 777 /startup.sh

然后执行脚本:

ENTRYPOINT ["./startup.sh"]
RUN ["./startup.sh"]
RUN ./startup.sh

【问题讨论】:

  • 您需要先创建一个用户,然后使用该用户才能执行此操作
  • 您是否尝试在主机本身中授予 +x 权限?

标签: docker ubuntu google-cloud-platform dockerfile


【解决方案1】:

您在此处缺少添加用户以更改权限 More Info

RUN useradd -ms /bin/bash  myuser

【讨论】:

    【解决方案2】:

    尝试在你的 docker 文件中添加这些行。

    RUN chown -R admin:admin /
    RUN chmod 755 /
    

    只需将管理员权限授予/ 根目录即可。

    您的 docker 文件将如下所示

    FROM alpine:3.8
    ENV LANG C.UTF-8
    RUN set -x && \
        apk add --no-cache \
                  openrc \
                  bash \
                  libreswan \
                  xl2tpd \
                  ppp \
        && mkdir -p /var/run/pluto \
        && mkdir -p /var/run/xl2tpd \
        && touch /var/run/xl2tpd/l2tp-control
    COPY ipsec.conf /etc/ipsec.conf
    COPY ipsec.secrets /etc/ipsec.secrets
    COPY xl2tpd.conf /etc/xl2tpd/xl2tpd.conf
    COPY options.l2tpd.client /etc/ppp/options.l2tpd.client
    COPY startup.sh /
    RUN chown -R admin:admin /
    RUN chmod 755 /
    CMD ["./startup.sh"]
    

    【讨论】:

      猜你喜欢
      • 2021-12-20
      • 2021-10-10
      • 2020-10-18
      • 2016-04-15
      • 2013-04-14
      • 1970-01-01
      • 2014-07-15
      • 2015-07-10
      • 1970-01-01
      相关资源
      最近更新 更多