StefanScherer / dockerfiles-windows

Various Dockerfiles for Windows Containers
MIT License
1.11k stars 396 forks source link

npm start issue with node Windows image #446

Closed dmbarry86 closed 3 years ago

dmbarry86 commented 4 years ago

Description

First off, thanks for creating the Node Windows images 👍

I've created an example react-app using npx create-react-app. I am then trying to host this inside your "12.18.3-windowsservercore-2019" image. I get an error regarding file not found when trying to execute npm start as entry CMD.

Error

image

Example Dockerfile

FROM stefanscherer/node-windows:12.18.3-windowsservercore-2019
WORKDIR /usr/src/react-app
COPY ./react-app/ /usr/src/react-app
RUN npm install
EXPOSE 3000
CMD [ "npm", "start" ]

If I replace the CMD [ "npm", "start" ] with something like CMD [ cmd.exe ] and then run the container interactively and execute npm start from within there it runs just fine. It appears to be an issue when npm start is used as entry CMD. Could it be npm is not on the path somehow? The RUN npm install step works just fine though.

Machine details

I'm running Windows 10 Pro. docker version image

dmbarry86 commented 4 years ago

A small update after some further bashing. If I switch to the shell version of CMD, i.e. CMD npm start then it works. I guess it is maybe looking for an executable which it can't find? However, when I do this the container then immediately shuts down. When used with compose I then need to add stdin_open: true and tty: true options to docker-compose file to keep the container alive.

The CMD [ "npm", "start" ] works fine with Linux Node containers and I don't need to add the extra options to docker-compose. Do you know how they handle it in the Linux containers? Is it possible to make the Windows container syntax equivalent or am I stuck with the differences? I'm currently in the process of migrating one of our Node apps over from Linux to Windows containers, thus my questions. Appreciate any insight you could give.

StefanScherer commented 4 years ago

Thanks for the detailed report.

Oh yes, npm couldn‘t be found. That‘s because CMD does not look for other extensions than .exe and .bat. The npm command is a npm.cmd - put that into your Dockerfile, that should work.

webuniverseio commented 4 years ago

yarn.cmd did the trick, thank you!

version: "2.1"

services:
  app:
    build: .
    command: "yarn.cmd install && yarn.cmd start"
    ports:
      - 3000:3000
    working_dir: c:/app
    volumes:
      - ./:c:/app
    # restart: unless-stopped