【问题标题】:Error creating docker image: "/bin/sh: 1: -E: not found"创建 docker 映像时出错:“/bin/sh: 1: -E: not found”
【发布时间】:2022-02-11 00:15:30
【问题描述】:

我尝试从 Dockerfile 构建映像,但收到此错误:

/bin/sh: 1: -E: not found
The command '/bin/sh -c curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | -E bash -' returned a non-zero code: 127.

我的 Dockerfile 是:

ARG NODE_VERSION
ARG ANGULAR_VERSION


WORKDIR /

RUN apt-get update -y 
RUN apt-get upgrade -y 
RUN apt-get install bash -y  
RUN apt-get install curl -y 
RUN curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | -E bash - 
RUN apt-get install nodejs
RUN npm install @angular/cli@$ANGULAR_VERSION
RUN mkdir dpa-frontend
ADD --chmod=777 /home/dockerCoach/dap-frontend/* /dpa-frontend
WORKDIR /dpa-frontend
RUN npm install 
RUN ng build --configuration=production


FROM ubuntu:latest AS deploy

ARG NODE_VERSION

WORKDIR /

RUN apt-get update -y 
RUN apt-get upgrade -y 
RUN apt-get install bash -y 
RUN apt-get install curl -y

RUN  install curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | -E bash -
RUN npm install nodejs

RUN npm install -g pm2 &\
    pm2 update

WORKDIR /dap-frontend

COPY --from=build  /dpa-frontend/dist . 

EXPOSE 4000

CMD pm2 start "ng serve --host 0.0.0.0 --port 4000" --name "dpa-frontend"

【问题讨论】:

  • 在构建时是否传递了 NODE_VERSIONANGULAR_VERSION 的构建参数?有什么理由不从官方的 nodejs 图像之一开始作为您的基础?

标签: node.js bash docker


【解决方案1】:

我尝试从 Dockerfile 构建映像,但收到此错误:

/bin/sh: 1: -E: not found
The command '/bin/sh -c curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | -E bash -' returned a non-zero code: 127.

正如您在 Dockerfile RUN 以及上述错误中看到的那样

RUN  install curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | -E bash -

-E bash -没有sudo就没有意义

请更正

RUN  curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash -

由于您的 Dockerfile 中没有指定 USER <user>,因此在构建期间默认用户将是 root,因为您的父映像是 ubuntu。

请注意 Dockerfile 中的默认用户是父映像的用户,在您的情况下是 ubuntu:latest (FROM ubuntu:latest AS deploy)。默认情况下可以有非root的图像。

如果您在非 docker 环境中安装,您可以使用 curl -sL .... | sudo -E bash -

$ man sudo
   .....
-E, --preserve-env
    Indicates to the security policy that the user wishes to preserve their existing 
    environment variables. The security policy may return 
    an error if the user does not have permission to preserve the environment.

【讨论】:

    猜你喜欢
    • 2015-12-18
    • 2020-07-28
    • 2019-09-11
    • 2021-10-20
    • 1970-01-01
    • 2018-06-27
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    相关资源
    最近更新 更多