简体   繁体   English

Docker 映像无法在 AWS EC2 linux 上构建,但在 Windows 和 Mac 上构建时有效

[英]Docker image failing to build on AWS EC2 linux but works when built on Windows and Mac

When I run docker-compose build minexample with the following 3 files on Mac or Windows, the image is built successfully.当我在 Mac 或 Windows 上使用以下 3 个文件运行docker-compose build minexample时,图像构建成功。 But when I try to do the same thing on a AWS Linux 2 EC2 instance, it fails when running node-sass 's install script (see below).但是当我尝试在 AWS Linux 2 EC2 实例上做同样的事情时,它在运行node-sass的安装脚本时失败(见下文)。

After much trial and error over 2 days, I realized that the issue goes away if I lower react-scripts version to "3.0.0".经过 2 天的反复试验,我意识到如果我将react-scripts版本降低到“3.0.0”,问题就会消失。 That would also mean I need to lower eslint in my dev dependency (which I don't include in the minimal example) from 7.12.0 to 5.16.0.这也意味着我需要将我的开发依赖项(我不包括在最小示例中)中的 eslint 从 7.12.0 降低到eslint

I have a few questions:我有几个问题:

  1. How can the docker build succeed on Mac/Windows, yet fail on Linux? docker 构建如何在 Mac/Windows 上成功,但在 Linux 上失败? I thought containers were supposed to be an isolated environment yet somehow the host OS affected the outcome here.我认为容器应该是一个孤立的环境,但主机操作系统以某种方式影响了这里的结果。
  2. How do I figure out which node package versions are in conflict?如何确定哪个节点 package 版本有冲突? It took a lot of time via trial and error to figure out that lowering react-script 's version fixed (or hid) the problem.通过反复试验花了很多时间来弄清楚降低react-script的版本可以解决(或隐藏)问题。

package.json package.json

{
  "name": "minexample",
  "version": "1.0.0",
  "dependencies": {
    "node-sass": "4.12.0",
    "react": "16.14.0",
    "react-dom": "16.14.0",
    "react-router": "5.0.0",
    "react-router-dom": "5.0.0",
    "react-scripts": "4.0.2"
  },
  "devDependencies": {
  },
  "scripts": {
    "start": "react-scripts start"
  }
}

Dockerfile Dockerfile

FROM node:10.16.0-alpine AS build

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH

# cache dependencies
COPY ./package.json /usr/src/app/package.json
RUN npm install

docker-compose.yml docker-compose.yml

version: '3.7'

services:
  minexample:
    build:
      context: ./
      dockerfile: Dockerfile
    container_name: minexample

Error错误

> node-sass@4.12.0 install /usr/src/app/node_modules/node-sass 
> node scripts/install.js

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

Based on the comments.根据评论。

I tried to replicate the issue, but in my tests, the docker image is built successfully .我试图复制该问题,但在我的测试中,docker 映像已成功构建

Instance used, t2.small (have not tested using t2.micro ).使用的实例, t2.small (尚未使用t2.micro进行测试)。

Amazon Linux 2:亚马逊 Linux 2:

NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"

Docker Docker

docker --version
Docker version 19.03.13-ce, build 4484c46

docker-compose docker-compose

docker-compose --version
docker-compose version 1.28.4, build cabd5cfb

build image构建镜像

docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
a_minexample        latest              82968af21096        24 minutes ago      426MB
node                10.16.0-alpine      9dfa73010b19        20 months ago       75.3MB

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM