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

7
  • Can you share the output of your npm run start command ? Commented Aug 1, 2019 at 9:32
  • is your app running on port 3000? Commented Aug 1, 2019 at 9:35
  • Are you using Docker Toolbox? Commented Aug 1, 2019 at 9:51
  • @DavidMaze Yes, I am using Docker Toolbox. Commented Aug 1, 2019 at 13:46
  • 1
    If you’re using Docker Toolbox, try 192.168.99.100:3000 (or whatever IP address docker-machine ip returns). It runs a separate VM and localhost won’t reach it. Commented Aug 1, 2019 at 14:58

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

It's still not working, by the way, I am using docker toolbox on windows.
okay so this is the issue with docker toolbox here is the answer for your question stackoverflow.com/questions/42866013/…
updated pls check or follow the question for further investigation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.