6

I've been running json-server in a docker container for a while successfully with the following config:

Docker File:

FROM node:alpine    
EXPOSE 3000
COPY deploy/conf/mockBackend.json /opt/mockBackend.json
RUN yarn global add json-server
CMD ["json-server", "/opt/mockBackend.json"]

Run command:

docker run -d -p 3000:3000 --name mockbackend mockbackend

Recently this stopped working. I get ERR_CONNECTION_REFUSED in the browser.

By default json-server binds to 127.0.0.1, which could cause this issue if this is correct.

I don't know why it worked before, but binding json server to every interface with json-server -H 0.0.0.0 mockBackend.json makes it work again.

My problem now is that starting json-server that way in the image manually works fine, but when I change the CMD line of the Dockerfile to CMD ["json-server", "-H 0.0.0.0", "/opt/mockBackend.json"] I get the folloing error:

Docker log:

  \{^_^}/ hi!

  Loading /opt/mockBackend.json
  Done

  Resources
  http:// 0.0.0.0:3000/xxx
  http:// 0.0.0.0:3000/yyy

  Home
  http:// 0.0.0.0:3000

  Type s + enter at any time to create a snapshot of the database
events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo ENOTFOUND  0.0.0.0
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:50:26)
Emitted 'error' event at:
    at GetAddrInfoReqWrap.doListen [as callback] (net.js:1498:12)

It looks like the json-server is starting fine, but then exits with the error. Any idea why this only happens when starting the container with the CMD line, but not when running the same json-server command manually inside the same image?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Pabi
  • 891
  • 3
  • 12
  • 18
  • 4
    The `-H` and `0.0.0.0` should be split like `CMD ["json-server", "-H", "0.0.0.0", "/opt/mockBackend.json"]` Not sure if that's the only issue here, but try correcting that first. – Jeff Storey Jun 10 '18 at 14:53
  • Thanks, that actually fixed the issue! Thoug I still don't unterstand why it worked before when json-server was bound to 127.0.0.1 – Pabi Jun 10 '18 at 15:01
  • The real error was a problem with my reverse proxy. The server is publicly available but hosted on a dynamic IP. All my dns scripts where working except the one for this mock Backend. Thats why it "randomly" stopped working once the dynamic IP changed. – Pabi Jun 21 '18 at 10:12

0 Answers0