2

I try to build an image for a client app (nextjs app), but the build keeps failing.

This is the docker file:

FROM node:12.18.3
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app/
COPY package-lock.json /app/
RUN npm install
COPY . /app
RUN npm build
# start app
CMD [ "npm", "start" ]

It fails on the first step with this error:

Step 1/9 : FROM node:12.18.3
operating system is not supported

I followed this post https://stackoverflow.com/a/51071057/9608006 , changed the experimental settings to true, and it did pass the failing step.

but now it fails on the npm i step

npm notice
The command '/bin/sh -c npm install' returned a non-zero code: 4294967295: failed to shutdown container: container c425947f7f17ed39ed51ac0a67231f78ba7239ad199c7df979b3b442969a0a57 encountered an error during hcsshim::System::waitBackground: failure in a Windows system call: The virtual machine or container with the specified identifier is not running. (0xc0370110): subsequent terminate failed container c425947f7f17ed39ed51ac0a67231f78ba7239ad199c7df979b3b442969a0a57 encountered an error during hcsshim::System::waitBackground: failure in a Windows system call: The virtual machine or container with the specified identifier is not running. (0xc0370110)

I also get this warning in the start of this step:

Step 6/9 : RUN npm install
 ---> [Warning] The requested image's platform (linux/amd64) does not match the detected host platform (windows/amd64) and no specific platform was requested

I use windows 10, docker v20.10.5

What is the issue ?

EDIT 1 - Folder structure

the following is the base folders layer of the client app

  • .next
  • .vercel
  • components
  • enums
  • hooks
  • node_modules
  • pages
  • pubilc
  • store
  • styles
  • utils
  • .dockerIgnore
  • .env.local
  • next.config.js
  • package.json
  • server.js
Itay Tur
  • 683
  • 1
  • 15
  • 40

4 Answers4

3

You are trying to build Linux based image under Windows. It seems there is a problem in multiarch images of nodejs with tags version 12.

Try the answer under the post that you have tried: Click on the docker icon in the tray and switch into Linux containers.

https://stackoverflow.com/a/57548944/3040844

raxetul
  • 439
  • 5
  • 12
2

If you are using docker desktop.. just change docker desktop option for windows containers bydefault to linux containers and run your dockerfile again. enter image description here

Bhushan Gholave
  • 157
  • 2
  • 9
1

I think that the problem related to your base image , I used this Dockerfile for nextjs app in my side and it's working correctly :

# Dockerfile

# base image
FROM node:alpine

# create & set working directory
RUN mkdir -p /app
WORKDIR /app

# copy source files
COPY . /app

# install dependencies
RUN npm install

# start app
RUN npm run build
EXPOSE 3000
CMD npm run start

I hope that can help you to resolve your issue .

rassakra
  • 1,062
  • 5
  • 9
  • I copy/paste this docker file instead of mine. it failed in the 2nd step with similar error: "Step 2/8 : RUN mkdir -p /app ---> [Warning] The requested image's platform (linux/amd64) does not match the detected host platform (windows/amd64) and no specific platform was requested ---> Running in cd4ceeb43c5c The command '/bin/sh -c mkdir -p /app' returned a non-zero code: 4294967295:" – Itay Tur May 12 '21 at 20:58
  • can you share your project structure ? – rassakra May 12 '21 at 20:59
  • i added it in the first edit. let me know if it's not enough. thx for you help – Itay Tur May 12 '21 at 21:06
  • You are welcome , just let me know if this probelm not resolved – rassakra May 12 '21 at 21:07
  • yea it's still unresolved. after copy paste your dockerfile, i get this error on the 2nd step: Running in cd4ceeb43c5c The command '/bin/sh -c mkdir -p /app' returned a non-zero code: 4294967295 – Itay Tur May 12 '21 at 21:09
  • the problem appear when you execute the docker build -t image_name:image_tag . or when you execute docker run .... ? – rassakra May 12 '21 at 21:17
  • Build is the issue – Itay Tur May 13 '21 at 23:29
0

According to your dockerfile

FROM node:12.18.3
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app/
COPY package-lock.json /app/
RUN npm install
COPY . /app
RUN npm build
# start app
CMD [ "npm", "start" ]

You missed the right image FROM node:12.18.3 Correct way to do this FROM node:alpine3.12 or FROM ubuntu:18.04

FROM: FROM directive is probably the most crucial amongst all others for Dockerfiles. It defines the base image to use to start the build process. It can be any image, including the ones you have created previously. If a FROM image is not found on the host, Docker will try to find it (and download) from the Docker Hub or other container repository. It needs to be the first command declared inside a Dockerfile

Simplest Dockerfile with Node Image

FROM node:alpine3.12 
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY ..
RUN npm run build
EXPOSE 3000
CMD npm run start
SHUVO MUSA
  • 544
  • 6
  • 9