0

I'm trying to run a container described by the following Dockerfile:

FROM node:11.4.0 RUN npm install -g sh RUN npm install -g json-server WORKDIR /data VOLUME /data COPY db.json /data CMD json-server --watch db.json --port 3001 

and specifying the listening port by running:

 docker run -it -p 3001:3001 abelalejandro/json-server:final 

The container seems to be running fine and json-server is telling me it is serving my requests on port 3001 yet I can't get any joy when browsing http://localhost:3001

enter image description here

Am I missing something on publishing/exposing ports?

1 Answer 1

7

It is binding to localhost instead of 0.0.0.0 (any host).

You can change that by setting:

CMD json-server --watch db.json --host 0.0.0.0 --port 3001 

I'm assuming you are using https://github.com/typicode/json-server.

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

1 Comment

As a matter of good practice I would suggest adding EXPOSE instruction into your Dockerfile which would serve as a good documentation for the user running the container. Try building the image with/without EXPOSE instruction and do a docker image inspect abelalejandro/json-server:final to see more metadata attached to the image.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.