当我在 Mac 或 Windows 上使用以下 3 个文件运行 docker-compose build minexample
时,映像构建成功。但是当我尝试在 AWS Linux 2 EC2 实例上做同样的事情时,它在运行 node-sass
的安装脚本时失败(见下文)。
经过 2 天多次反复试验后,我意识到如果我将 react-scripts
版本降低到“3.0.0”,问题就会消失。这也意味着我需要将开发依赖项中的 eslint
(我不包括在最小示例中)从 7.12.0 降低到 5.16.0。
我有几个问题:
react-script
的版本可以解决(或隐藏)问题。{
"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"
}
}
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
version: '3.7'
services:
minexample:
build:
context: ./
dockerfile: Dockerfile
container_name: minexample
> 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
答案 0 :(得分:1)
基于评论。
我试图重现该问题,但在我的测试中,docker 映像成功构建。
已使用实例,t2.small
(尚未使用 t2.micro
进行测试)。
亚马逊 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 --version
Docker version 19.03.13-ce, build 4484c46
docker-compose
docker-compose --version
docker-compose version 1.28.4, build cabd5cfb
构建映像
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