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

  amazon-ec2, docker, node-sass, node.js, react-scripts

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:

  1. How can the docker build succeed on Mac/Windows, yet fail on Linux? I thought the container was supposed to be an isolated environment yet somehow the host OS affected it here.
  2. 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.


  "name": "minexample",
  "version": "1.0.0",
  "dependencies": {
    "node-sass": "4.12.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'

      context: ./
      dockerfile: Dockerfile
    container_name: minexample


> [email protected] 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

Source: Docker Questions