在pip安装需求后,docker构建失败,退出代码为137

vh0rcniy  于 2023-10-16  发布在  Docker
关注(0)|答案(7)|浏览(177)

我开始了一个新的django项目,并希望在我的ubuntu上将项目对接。当我运行docker-compose up --build时,我得到了一个奇怪的错误。它似乎与PIP安装要求有问题。
我试着搜索“退出代码137”的含义,大多数人说它是“内存不足”,但在我的情况下似乎不是这样。
Dockerfile:

FROM python:3.6
ENV PYTHONUNBUFFERED 1

RUN apt-get update && apt-get install apt-transport-https
RUN pip install --no-cache-dir pipenv

RUN mkdir /my-django
WORKDIR /my-django
ADD requirements.txt /my-django/

RUN pip install -r requirements.txt

docker-compose.yml:

version: '3'

services:
  db:
    image: postgres:11
    restart: unless-stopped
    volumes:
      - trkr-data:/var/lib/postgresql/data
    ports:
      - 11000:5432
    environment:
      - POSTGRES_DB='myDB'
      - POSTGRES_USER='myDB'
      - POSTGRES_PASSWORD='myDB'

  web:
    build: .
    restart: on-failure
    container_name: my-django
    image: trkr_web:latest
    volumes:
      - .:/my-django
    env_file:
      - ./.env
    command: python manage.py migrate && python manage.py runserver 0.0.0.0:8000
    ports:
      - "8000:8000"
    depends_on:
      - db

#sepcify volumes
volumes:
  my-data:

当我运行make up时(我有一个Makefile,up:docker-compose up --build),我得到了以下错误消息:

......
Collecting Django==2.2.3 (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/39/b0/2138c31bf13e17afc32277239da53e9dfcce27bac8cb68cf1c0123f1fdf5/Django-2.2.3-py3-none-any.whl (7.5MB)
Collecting django-environ==0.4.5 (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/9f/32/76295a1a5d00bf556c495216581c6997e7fa5f533b2229e0a9d6cbaa95ae/django_environ-0.4.5-py2.py3-none-any.whl
Collecting pipenv==2018.10.13 (from -r requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/90/06/0008f53835495fbbf6e31ced9119b8f517e1271bdefcf0d04aaa9f28dbf4/pipenv-2018.10.13-py3-none-any.whl (5.2MB)
Collecting psycopg2-binary==2.7.5 (from -r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/3f/4e/b9a5cb7c7451029f67f93426cbb5f5bebedc3f9a8b0a470de7d0d7883602/psycopg2_binary-2.7.5-cp36-cp36m-manylinux1_x86_64.whl (2.7MB)
Collecting pytz (from Django==2.2.3->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/3d/73/fe30c2daaaa0713420d0382b16fbb761409f532c56bdcc514bf7b6262bb6/pytz-2019.1-py2.py3-none-any.whl (510kB)
Collecting sqlparse (from Django==2.2.3->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/ef/53/900f7d2a54557c6a37886585a91336520e5539e3ae2423ff1102daf4f3a7/sqlparse-0.3.0-py2.py3-none-any.whl
Requirement already satisfied: pip>=9.0.1 in /usr/local/lib/python3.6/site-packages (from pipenv==2018.10.13->-r requirements.txt (line 3)) (18.1)
Requirement already satisfied: virtualenv in /usr/local/lib/python3.6/site-packages (from pipenv==2018.10.13->-r requirements.txt (line 3)) (16.7.2)
Requirement already satisfied: certifi in /usr/local/lib/python3.6/site-packages (from pipenv==2018.10.13->-r requirements.txt (line 3)) (2019.6.16)
Requirement already satisfied: virtualenv-clone>=0.2.5 in /usr/local/lib/python3.6/site-packages (from pipenv==2018.10.13->-r requirements.txt (line 3)) (0.5.3)
Requirement already satisfied: setuptools>=36.2.1 in /usr/local/lib/python3.6/site-packages (from pipenv==2018.10.13->-r requirements.txt (line 3)) (40.6.2)
Installing collected packages: pytz, sqlparse, Django, django-environ, pipenv, psycopg2-binary
  Found existing installation: pipenv 2018.11.26
    Uninstalling pipenv-2018.11.26:
      Successfully uninstalled pipenv-2018.11.26
Successfully installed Django-2.2.3 django-environ-0.4.5 pipenv-2018.10.13 psycopg2-binary-2.7.5 pytz-2019.1 sqlparse-0.3.0
Killed
ERROR: Service 'web' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 137
Makefile:2: recipe for target 'up' failed

这个问题可以通过RUN pip3 install --no-cache-dir -r requirements.txt解决。

omqzjyyz

omqzjyyz1#

我在我的Windows机器上得到下面的错误:
被杀错误:服务'kafka-asr'无法构建:命令“/bin/sh -c pip install --no-cache-dir -r requirements.txt”返回非零代码:137
在增加Docker内存后,错误得到了解决。

  • 右键点击docker ->设置->高级

我将内存从2304增加到2816,然后点击Apply。

slwdgvem

slwdgvem2#

加上问题末尾的答案:
此问题由RUN pip3 install --no-cache-dir -r requirements.txt解决

xv8emn3q

xv8emn3q3#

解决方案

分配更多的RAM给Docker(如@PravinKumar上面所说)。
以下是各种Docker版本的设置屏幕screenshots

理由

code 137错误发生在 Linux/OS X 上,实际上意味着Fatal error signal "9"explanation here),对应于Out Of Memory异常,后跟SIGKILL信号终止进程。

有用链接

6mw9ycah

6mw9ycah4#

对我来说,在增加存储大小而不是RAM大小后,错误得到了解决。仅供参考。
我经常得到下面的错误。

. . .
Killed
The command '/bin/sh -c pip install -r /tmp/requirements.txt' returned a non-zero code: 137

在Mac中,如果您使用的是最新版本的Docker,请执行以下操作。
Docker =>首选项.=> Docker Engine =>像下面这样更改实验特性。这里我提到了30GB,你可以根据你的需要增加。

{
      "experimental": false,
      "builder": {
        "gc": {
          "enabled": true,
          "defaultKeepStorage": "30GB"
        }
      },
      "features": {
        "buildkit": false
      }
    }
r6vfmomb

r6vfmomb5#

我无法尝试this solution,因为我正在使用的服务器主机上的用户权限。
我不知道为什么,但是使用这个版本的Docker compose

mkdir -p ~/.docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
chmod +x ~/.docker/cli-plugins/docker-compose

帮助解决这个问题。现在我们不用

docker-compose up --build

我使用了(docker和compose之间没有破折号)

docker compose up --build

我注意到的警告是,当重建我的镜像时,新的容器没有使用"docker compose up --build"重新创建。我现在可以使用"docker-compose up --build"而不用得到code 137 error,因为需求被缓存了。

pgpifvop

pgpifvop6#

由于RAM限制,我在Windows上遇到了类似的问题。最初,我在.wslconfig文件中为Docker设置了最大RAM使用量,因为我只有8 GB的RAM,但这不足以创建我的镜像。升级到24 GB后,删除了位于c:\ Users\ [your_account]. wslconfig的.wslconfig文件。这允许Docker使用尽可能多的RAM来创建镜像,并且它可以工作!!

7d7tgy0s

7d7tgy0s7#

此错误通过Dockerfile中的以下更改解决:

RUN pip install --upgrade pip; \
    pip install -r requirements.txt

COPY . /trkr-django

现在构建成功,但我遇到了数据库连接错误。

相关问题