3

I'm having trouble making HTTP requests to my docker container (it's a Node.js API that communicates with a Redis database), which runs inside a VM (Docker Toolbox).

I've set up my Dockerfile and docker-compose.yml with the desired ports. Built them and ran ("up") them successfully.

FROM node:8.15

WORKDIR /redis_server

COPY package.json package-lock.json ./

RUN npm install

COPY . ./

EXPOSE 8080

CMD ["npm", "start"]
version: '3'
services:
  web:
    build: .
    depends_on:
      - db

  db:
    image: redis
    ports:
      - "6379:6379"

redis.js

const PORT = 6379
const HOST = 'db'

server.js (express.js)

const PORT = '0.0.0.0:8080'

I build the container succesfully, then use a HTTP request service to test a GET. Since I run Docker Toolbox and that the VM is on host 192.168.99.100, I send my requests to http://192.168.99.100:8080.

This does not work, the error message that appears in my Visual Studio Code is "Connection is being rejected. The service isn't running on the server, or incorrecte proxy settings in vscode, or a firewall is blocking requests. Details: Error: connect ECONNREFUSED 192.168.99.100:8080."

Not sure where to go from here. I don't consider myself knowledgeable on things network.

tomkcey
  • 97
  • 2
  • 8
  • Exposing port 8080 is not enough; you may run multiple such containers so Docker allocates a new port for you. You need to map the `web` container port 8080 to your host port 8080 like you did with redis. – Botje Jul 02 '19 at 14:04
  • Thanks. I've tried that, but it's still giving me the same error. I did a rebuild, and still does the same thing. Any idea? – tomkcey Jul 02 '19 at 14:24

1 Answers1

2

It’s because you have not opened port on host. You may try:

version: '3'
services:
  web:
    build: .
    ports:
      - "8080:8080"
    depends_on:
      - db

  db:
    image: redis
    ports:
      - "6379:6379"
rajesh-nitc
  • 5,049
  • 3
  • 25
  • 33