命令在heroku命令行上工作,但不在推送的docker映像中工作
我有以下Dockerfile:命令在heroku命令行上工作,但不在推送的docker映像中工作,docker,clojure,leiningen,Docker,Clojure,Leiningen,我有以下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 /us
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"
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"]
从url下载lein,并将其放入/usr/bin。但仍然是
运行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一次性dyno上,该命令有效
$/bin/sh-c“lein-v”问题在于docker
RUN
希望命令按原样不带引号,或者作为命令及其参数的数组:
RUN lein-v
或RUN[“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的前十五个步骤:
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"
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
这是dockerfile的一部分,因此我希望lein命令在java not found上失败,而不是在lein not found上失败。有没有更好的方法来运行Dockerfile的一部分,因为运行整个Dockerfile进行调试需要四倍的时间?问题不是“lein not found”,而是
“lein-v”
not found,因为docker认为它是单个可执行文件<代码>运行“lein”是有效的,但正确的(推荐的afaik)是运行[“lein”,“-v”]
您可以调试它,只需留下所需的部分,并在容器中进行实验,比如在dockerfile中运行注释“lein-v”,构建它,然后输入容器shell docker RUN-ti${container\u id}/bin/sh并尝试在那里运行一些命令。此外,dockertile中的更改上面的部分不应该重建,所以实际上每次我猜它不应该那么长。就像现在更改上一个RUN命令一样,它应该很快重新生成。RUN[“lein”,“-v”]不起作用。我的编辑有(几乎)整个dockerfileIt在实际文件中有逗号