When I run docker-compose build minexample with the following 3 files on Mac or Windows, the image is built successfully. 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).
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". 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.
I have a few questions:
- How can the docker build succeed on Mac/Windows, yet fail on Linux? I thought containers were supposed to be an isolated environment yet somehow the host OS affected the outcome here.
- How do I figure out which node package versions are in conflict? It took a lot of time via trial and error to figure out that lowering
react-script's version fixed (or hid) the problem.
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
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
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