JasonMHirst
JasonMHirst

Reputation: 576

Running React app in Docker (Basic question)

There's quite a few questions in SO about running a React App in Docker, and while I believe I'm following the instructions to the letter, it's still not working for me and was wondering if anyone has a clear solution.

In short I have the following in my Dockerfile

ARG VARIANT="14-buster"
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install 

COPY . .

EXPOSE 3000

This works, but I have to manually run NPM START in the terminal within VSCode in order for my browser to open http://localhost:3000

I've read in various posts that either adding RUN npm start or RUN ['CMD', 'START']will achieve what I want, but absolutely none of those work at all. Sure enough the only to make it work is running NPM START in the terminal of VSCode.

Is there something utterly obvious I'm missing? I just want to be able to have this app running in a container, without VSCode, and if I need access to it, just type http://localhost:3000 in my browser and get access to the Dockerized image.

Upvotes: 0

Views: 45

Answers (1)

luisbar
luisbar

Reputation: 778

You can do that adding at the end of your dockerfile the following step CMD npm start or CMD ["npm", "start"], here you go more information

Upvotes: 1

Related Questions