I have 3 containers in my docker compose: 2 webserver, 1 mongodb instance. Weather-service sends http request to Main-service, so in my docker configuration I linked that two containers. To reach main-service container from weather-service I use this address: http://main-service:3000 When I run: docker-compose up --build, I receive an error for connection. weather-service dockerfile:
FROM node:8-alpine
EXPOSE 4000
ARG NODE_ENV
ENV NODE_ENV $NODE_ENV
RUN mkdir /app
WORKDIR /app
ADD package.json yarn.lock /app/
RUN yarn --pure-lockfile
ADD . /app
CMD ["yarn", "docker:start"]
main-service dockerfile
FROM node:8-alpine
EXPOSE 3000
ARG NODE_ENV
ENV NODE_ENV $NODE_ENV
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh
RUN mkdir /app
WORKDIR /app
ADD package.json yarn.lock /app/
RUN yarn --pure-lockfile
ADD . /app
CMD ["yarn", "docker:start"]
docker-compose.yml
version: "3"
services:
main-service:
build: main-service
volumes:
- .:/app/main-service
ports:
- "3000:3000"
env_file:
- ./main-service/.env
networks:
- app-network
links:
- weather-service
weather-service:
build: weather-service
environment:
- MONGO_URI=mongodb://mongodb:27017/forecast-data
volumes:
- .:/app/weather-service
ports:
- "4000:4000"
env_file:
- ./weather-service/.env
networks:
- app-network
depends_on:
- mongodb
mongodb:
image: mongo
networks:
- app-network
ports:
- "27017:27017"
networks:
app-network:
external: true
This is the error which I receive:
weather-service_1 | 0|index | RequestError: Error: connect ECONNREFUSED 172.23.0.4:3000 weather-service_1 | 0|index | at new RequestError (/app/node_modules/request-promise-core/lib/errors.js:14:15) weather-service_1 | 0|index | at Request.plumbing.callback (/app/node_modules/request-promise-core/lib/plumbing.js:87:29) weather-service_1 | 0|index | at Request.RP$callback [as _callback] (/app/node_modules/request-promise-core/lib/plumbing.js:46:31) mongodb_1 | 2018-01-06T13:46:19.281+0000 I STORAGE [conn2] createCollection: forecast-data.refreshtokens with generated UUID: 85c26f12-464f-4d69-a969-713acf634c6f weather-service_1 | 0|index | at self.callback (/app/node_modules/request/request.js:186:22) weather-service_1 | 0|index | at emitOne (events.js:116:13) weather-service_1 | 0|index | at Request.emit (events.js:211:7) weather-service_1 | 0|index | at Request.onRequestError (/app/node_modules/request/request.js:878:8) weather-service_1 | 0|index | at emitOne (events.js:116:13) weather-service_1 | 0|index | at ClientRequest.emit (events.js:211:7) weather-service_1 | 0|index | at Socket.socketErrorListener (_http_client.js:387:9) weather-service_1 | 0|index | at emitOne (events.js:116:13) weather-service_1 | 0|index | at Socket.emit (events.js:211:7) weather-service_1 | 0|index | at emitErrorNT (internal/streams/destroy.js:64:8) weather-service_1 | 0|index | at _combinedTickCallback (internal/process/next_tick.js:138:11) weather-service_1 | 0|index
| at process._tickDomainCallback (internal/process/next_tick.js:218:9)
app-network
withdocker network create -d overlay app-network
? - Ishan Thilina Somasiri