【问题标题】:System hangs after pip install in docker build在 docker build 中安装 pip 后系统挂起
【发布时间】:2020-07-17 13:39:49
【问题描述】:

我正在运行以下 Dockerfile

FROM python:3.6.9
WORKDIR /app
COPY . /app

# install dependencies
RUN pip3 install tensorflow==1.15
RUN pip3 install -r requirements.txt

# define the port number
EXPOSE 5000

# run
CMD ["python3", "./index.py"]

我正在尝试构建部署在 Flask 应用程序上的 ML 模型的图像。当我运行该命令时,我的系统会挂起。

sudo docker build -t lhp .

我必须重新启动系统才能重新运行 docker。构建执行在RUN pip3 install tensorflow==1.15 处停止。我已经使用 pip 和 pip3 多次尝试过,但错误仍然存​​在。我也尝试用其他 python 包替换 tensorflow。问题似乎出在 pip 而不是特定的 python 包。请帮我解决这个问题。以下是我的终端的副本。

aishwarya@aishwarya-ThinkPad-W540:/media/aishwarya/2E068D88068D522F/lhp$ sudo docker build -t lhpoc8 .
Sending build context to Docker daemon  452.5MB
Step 1/7 : FROM python:3.6.9
 ---> 5bf410ee7bb2
Step 2/7 : WORKDIR /app
 ---> Running in fefe94814764
Removing intermediate container fefe94814764
 ---> e261c29f7c96
Step 3/7 : COPY . /app
 ---> babae5a3fee8
Step 4/7 : RUN pip3 install tensorflow==1.15
 ---> Running in 7e4d9d7e5353

就是这样。这是它停止的地方。

更新

这是图像历史记录

aishwarya@aishwarya-ThinkPad-W540:/media/aishwarya/2E068D88068D522F/lhp$ sudo docker image history 1c7f12b2e283
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
1c7f12b2e283        23 minutes ago      /bin/sh -c #(nop) COPY dir:235abf6dd10dddd25…   452MB               
88bcbf8e9815        23 minutes ago      /bin/sh -c #(nop) WORKDIR /app                  0B                  
5bf410ee7bb2        4 months ago        /bin/sh -c #(nop)  CMD ["python3"]              0B                  
<missing>           4 months ago        /bin/sh -c set -ex;   wget -O get-pip.py "$P…   6.25MB              
<missing>           4 months ago        /bin/sh -c #(nop)  ENV PYTHON_GET_PIP_SHA256…   0B                  
<missing>           4 months ago        /bin/sh -c #(nop)  ENV PYTHON_GET_PIP_URL=ht…   0B                  
<missing>           4 months ago        /bin/sh -c #(nop)  ENV PYTHON_PIP_VERSION=19…   0B                  
<missing>           4 months ago        /bin/sh -c cd /usr/local/bin  && ln -s idle3…   32B                 
<missing>           4 months ago        /bin/sh -c set -ex   && wget -O python.tar.x…   86.2MB              
<missing>           4 months ago        /bin/sh -c #(nop)  ENV PYTHON_VERSION=3.6.9     0B                  
<missing>           4 months ago        /bin/sh -c #(nop)  ENV GPG_KEY=0D96DF4D4110E…   0B                  
<missing>           4 months ago        /bin/sh -c apt-get update && apt-get install…   17.1MB              
<missing>           4 months ago        /bin/sh -c #(nop)  ENV LANG=C.UTF-8             0B                  
<missing>           4 months ago        /bin/sh -c #(nop)  ENV PATH=/usr/local/bin:/…   0B                  
<missing>           4 months ago        /bin/sh -c set -ex;  apt-get update;  apt-ge…   510MB               
<missing>           4 months ago        /bin/sh -c apt-get update && apt-get install…   145MB               
<missing>           4 months ago        /bin/sh -c set -ex;  if ! command -v gpg > /…   17.5MB              
<missing>           4 months ago        /bin/sh -c apt-get update && apt-get install…   16.5MB              
<missing>           4 months ago        /bin/sh -c #(nop)  CMD ["bash"]                 0B                  
<missing>           4 months ago        /bin/sh -c #(nop) ADD file:9b7d9295bf7e8307b…   114MB

【问题讨论】:

  • 你确定它没有挂在下一行:RUN pip3 install -r requirements.txt?这似乎更合理
  • 不。我交换了 2 个RUN pip3 命令,错误总是出现在先出现的那个。
  • 那么问题似乎出在对pip3 命令的调用中。它是可访问的和存在的吗?例如在我的机器上也安装了perlpip 指的是perl 脚本,我需要使用完整路径来访问pythonpip。类似的情况可能在这里
  • 如何检查它是否可访问或存在? pip3不是和父python3.6.9镜像一起来的吗?
  • 有时需要额外设置pip.pypa.io/en/stable/installing

标签: python docker pip dockerfile docker-build


【解决方案1】:

首先安装 pip(在您的 dockerfile 中按此顺序)

RUN pip install -U pip

然后运行 ​​pip install (ex. for python3)

RUN python3 -m pip install --no-cache-dir -r requirements.txt

【讨论】:

  • 现在我的系统挂在RUN pip install -U pipXD
  • @AishwaryaHarpale 不确定是否仍需要帮助,但请确保您在使用 docker 时没有开启 VPN。您将无法在 Docker 映像中访问 Internet,这会导致您的系统在不断尝试更新时冻结。
  • @RakshitKothari 这个问题是因为我的根目录空间不足,我使用符号链接将我的 /var/lib/docker 导出到了外部驱动器。我扩大了存储空间并再次下载了docker。现在一切都很好。
【解决方案2】:

所以基本上没有任何效果。由于一些符号链接,我面临错误,因为我已将 Docker 存储转移到另一个磁盘。我卸载了 Docker,然后最终卸载了 Ubuntu。增加了我的 Ubuntu 分区大小,直到它大到可以存储 docker 图像。重新安装了Ubuntu,Docker。现在我与快乐而成功的 docker builds 和平相处。

【讨论】:

    猜你喜欢
    • 2021-07-30
    • 2016-02-28
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 2021-11-29
    • 2019-12-09
    • 2017-08-02
    • 2013-11-11
    相关资源
    最近更新 更多