命令适用于 heroku 命令行,但不适用于推送的 docker 映像



我有以下Dockerfile:

FROM ubuntu:latest
RUN apt-get -qq update && apt-get -qq -y install wget
&& wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein 
&& chmod a+x lein 
&& cp lein /usr/bin 
RUN "lein -v"

从 URL 下载 Lein,并将其放入/usr/bin 中。但仍然

RUN lein -v

命令不起作用。

我收到错误:

remote: Step 18/22 : RUN lein -v        
remote:  ---> Running in e5f404275fe2        
remote: /bin/sh: 1: lein -v: not found        
remote: The command '/bin/sh -c lein -v' returned a non-zero code: 127        
remote: 
remote: Verifying deploy...
remote: 
remote: !   Push rejected to appname 

在 Heroku 一次性测功机本身上,该命令有效。

$/bin/sh -c "lein -v">

问题是 dockerRUN期望命令不加引号,或者作为命令数组及其参数:

RUN lein -vRUN ["lein", "-v"]之一应该可以解决问题。

另一个问题是,您的映像没有安装 Java,因此该命令无论如何都会失败。所以你需要以某种方式安装它。您的最终 Dockerfile 可能如下所示:

FROM ubuntu:latest
RUN apt-get -qq update && apt-get -qq -y install wget
&& wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein 
&& chmod a+x lein 
&& cp lein /usr/bin 
RUN DEBIAN_FRONTEND=noninteractive 
apt-get -y install default-jre-headless && 
apt-get clean && 
rm -rf /var/lib/apt/lists/*
RUN ["lein", "-v"]

--编辑--

事实上,添加 java 依赖项并更改为RUN ["lein", "-v"]也不起作用。以下是 Dockerfile 的前十五个步骤:

ARG CLOJURE_TOOLS_VERSION=1.10.1.507
RUN apt-get -qq update && apt-get -qq -y install curl wget bzip2 openjdk-8-jdk-headless
&& curl -sSL https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -o /tmp/miniconda.sh 
#    && curl -sSL https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -o /tmp/miniconda.sh 
&& bash /tmp/miniconda.sh -bfp /usr/local 
&& rm -rf /tmp/miniconda.sh 
&& conda install -y python=3 
&& conda update conda 
&& curl -o install-clojure https://download.clojure.org/install/linux-install-${CLOJURE_TOOLS_VERSION}.sh 
&& chmod +x install-clojure 
&& ./install-clojure && rm install-clojure 
# no need to install lein
&& wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > /usr/bin/lein 
&& chmod 777 /usr/bin/lein 


&& apt-get -qq -y autoremove 
&& apt-get autoclean 
&& rm -rf /var/lib/apt/lists/* /var/log/dpkg.log 
&& conda clean --all --yes
ENV PATH /usr/bin:$PATH
ENV NODE_VERSION=12.18.1
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version


# ENV PATH /opt/conda/bin:$PATH
# RUN conda create -n pyclj python=3.7 && conda install -n pyclj numpy mxnet 
#     && conda install -c conda-forge opencv
# ## To install pip packages into the pyclj environment do
# RUN conda run -n pyclj python3 -mpip install numpy opencv-python
FROM openjdk:8-alpine
RUN ["lein", "-v"]

它给出了错误

remote: Step 15/19 : RUN ["lein", "-v"]        
remote:  ---> Running in b817213d45b5        
remote: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: "lein": executable file not found in $PATH": unknown        
remote: 
remote: Verifying deploy...
remote: 
remote: !   Push rejected to

相关内容

最新更新