0

I am trying to develop a simple react app and I am trying to use docker for running a development server, but it is not connecting up in the browser

Here is the Dockerfile.dev

FROM node:alpine

WORKDIR /app

COPY package.json .
RUN npm install

COPY . .

CMD ["npm", "run", "start"]

EXPOSE 3000

Here are the two commands to create and run the container

docker build -f Dockerfile.dev .
docker run -p 3000:3000 <image_id>

It's starting a development server as the normal npm start does but it is not running in the browser at localhost:3000

tensor
  • 733
  • 1
  • 13
  • 22

1 Answers1

1

You container will exist if you did not mention -it or -dit (if its not typo in question). The reason being stopped immediately because bash can't find any pseudo terminal to be allocated. You have to specify -it or -dit so that bash or sh can be allocated to a pseudo-terminal.

docker run --name test -p 3000:3000 <image_id>

If you run docker ps | grep test you will see in the output

"/bin/bash" {some} seconds ago Exited (0) {some} seconds ago

Now try to run with

docker run --name test -dit -p 3000:3000 <image_id>

or

docker run --name test -it -p 3000:3000 <image_id>

Good to go localhost:3000

Updated:

For window, docker toolbox follows these steps.

Click the appropriate machine (probably the one labeled "default") Settings

  • Network > Adapter 1 > Advanced > Port Forwarding
  • Click "+" to add a new Rule Set Host Port 3000 & Guest Port 3000; be sure to leave Host IP and Guest IP empty

Run the command:

docker run -dit -p 3000:3000 ${image_id}

docker-toolbox-localhost

Adiii
  • 54,482
  • 7
  • 145
  • 148
  • It's still not working, by the way, I am using docker toolbox on windows. – tensor Aug 01 '19 at 13:58
  • 1
    okay so this is the issue with docker toolbox here is the answer for your question https://stackoverflow.com/questions/42866013/docker-toolbox-localhost-not-working – Adiii Aug 01 '19 at 14:05
  • 1
    updated pls check or follow the question for further investigation – Adiii Aug 01 '19 at 14:12