我是docker的新手,我需要在docker环境中运行代码。
我在构建Dockerfile时出错:
我正在通过hyper-V运行Ubuntu 20.04,并且在构建Dockerfile时,收到以下消息:
Step 4/20 : RUN curl -o ~/miniconda.sh -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && chmod +x ~/miniconda.sh && ~/miniconda.sh -b -p /opt/conda && rm ~/miniconda.sh && /opt/conda/bin/conda install numpy pyyaml scipy ipython mkl && /opt/conda/bin/conda install -c soumith magma-cuda90 && /opt/conda/bin/conda clean -ya <br />
---> Running in 9758f4fe60a4 <br />
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
/bin/sh: 1: /opt/conda/bin/conda: not found
The command '/bin/sh -c curl -o ~/miniconda.sh -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && chmod +x ~/miniconda.sh && ~/miniconda.sh -b -p /opt/conda && rm ~/miniconda.sh && /opt/conda/bin/conda install numpy pyyaml scipy ipython mkl && /opt/conda/bin/conda install -c soumith magma-cuda90 && /opt/conda/bin/conda clean -ya' returned a non-zero code: 127
Dockerfile的:# PyTorch Install
FROM nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
curl \
vim \
emacs \
parallel \
ca-certificates \
libjpeg-dev \
hdf5-tools \
libpng-dev &&\
rm -rf /var/lib/apt/lists/*
RUN mkdir ~/.parallel && touch ~/.parallel/will-cite
RUN sudo curl -o ~/miniconda.sh -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
chmod +x ~/miniconda.sh && \
~/miniconda.sh -b -p /opt/conda && \
rm ~/miniconda.sh && \
/opt/conda/bin/conda install numpy pyyaml scipy ipython mkl && \
/opt/conda/bin/conda install -c soumith magma-cuda90 && \
/opt/conda/bin/conda clean -ya
ENV PATH /opt/conda/bin:$PATH
# This must be done before pip so that requirements.txt is available
WORKDIR /opt/pytorch
COPY . .
RUN conda install pytorch torchvision -c pytorch
#
# Now install the julia dependencies.
#
WORKDIR /opt/julia
RUN pip install pandas matplotlib utils argh biopython
RUN conda install networkx joblib
RUN apt-get update && apt-get install -y curl
RUN mkdir /julia
RUN curl -L https://julialang-s3.julialang.org/bin/linux/x64/0.6/julia-0.6.2-linux-x86_64.tar.gz | tar -C /julia --strip-components=1 -xzf -
ENV PATH "/julia/bin:$PATH"
RUN julia -e "Pkg.init()"
COPY setup.jl /julia/setup.jl
RUN julia /julia/setup.jl
WORKDIR /root/hyperbolics
ENV PYTHONPATH /root/hyperbolics
当我在命令提示符下直接在RUN下尝试命令时,它运行良好。但是,当我构建Dockerfile,julia,pip等时,每个命令都是
'not found'
。(当我注释掉conda ...部分时)我怎么解决这个问题?
最佳答案
/bin/sh: 1: /opt/conda/bin/conda: not found
错误是由于未正确安装conda引起的。这是因为您下载的miniconda.sh
文件(带有curl -o ~/miniconda.sh -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
)是一个空文件。
发生这种情况是因为curl by default doesn't follow redirects和来自上面url的响应发送了重定向,而不是直接发送miniconda.sh
文件。您可以通过检查网址的标题来验证这一点(例如curl -i https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
显示HTTP 301重定向状态代码)。
您可以通过在curl命令中提供-L标志来告诉curl遵循重定向,从而解决此问题。 :
(我还必须删除sudo
)
RUN curl -L -o ~/miniconda.sh -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
chmod +x ~/miniconda.sh && \
~/miniconda.sh -b -p /opt/conda && \
rm ~/miniconda.sh && \
/opt/conda/bin/conda install numpy pyyaml scipy ipython mkl && \
/opt/conda/bin/conda install -c soumith magma-cuda90 && \
/opt/conda/bin/conda clean -ya
这是一些调试信息/研究:
您可以通过查看以上代码段中curl的输出来验证空白
miniconda.sh
是问题所在。看起来有点神秘,但您实际上什么都没有下载 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
当我尝试构建添加了-L标志的docker镜像时,输出如下所示: % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0
100 88.7M 100 88.7M 0 0 11.9M 0 0:00:07 0:00:07 --:--:-- 34.7M
您还可以通过删除下载/运行部分之前的所有内容来手动检查miniconda.sh的内容(例如,将所有内容都保留到这一部分)
RUN sudo curl -o ~/miniconda.sh -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
chmod +x ~/miniconda.sh && \
~/miniconda.sh -b -p /opt/conda
然后运行sudo docker run -it containername /bin/bash
并检查miniconda.sh的内容(cat ~/miniconda.sh
,它显示文件为空)。关于linux - 构建docker:找不到opt/conda/bin/conda,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63359198/