Docker撰写构建退出137(内存不足)

时间:2017-09-14 16:54:22

标签: docker docker-compose

我有一个内存受限的环境(约160mb ram free),使用简单的docker-compose文件运行服务:

version: "2"

services:
  nginx:
    build: ./nginx
    restart: always
    ports:
      - "80:80"
    depends_on:
      - admin-app
  admin-app:
    build: .
    restart: always
    environment:
      - PORT=80

我需要重建并重新启动它,但当我使用docker-compose up -d --build执行此操作时,收到错误:

ERROR: Service 'admin-app' failed to build: The command '/bin/sh -c npm install' returned a non-zero code: 137

这是显示失败版本的docker ps -a的输出:

75f0695af77f "/bin/sh -c 'npm i..."   11 minutes ago   Exited (137) 8 minutes ago
44d7d9e8ec06 "/bin/sh -c 'npm i..."   15 minutes ago   Exited (137) 14 minutes ago
4e3f159dd183 "/bin/sh -c 'npm i..."   19 minutes ago   Exited (137) 17 minutes ago

如何在docker-compose中设置构建内存限制?

1 个答案:

答案 0 :(得分:1)

docker-compose没有为构建设置内存限制的选项。您最好的选择是单独构建

docker build -m 60m .
docker build -m 60m nginx

然后运行docker-compose up -d命令