Reputation: 381
I am trying to build a docker-compose file that run a node.js graphql api that uses prisma and mongodb. But I got an error request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466 when ever I try to send requests from graphql playground and the same error when I run prisma deploy or just try to ping http:localhost:4466 from inside the graphql container.
I have tried to use the default network and creating new network but I got the same error. I have tried to use links (which is deprecated) in version 3 but also I got the same error.
P.S I can open the playground of prisma normally in the browser with the link: http://localhost:4466
This is my docker-compose file:
version: '3'
services:
web:
build: .
networks:
net:
ports:
- "80:4000"
command: wait-for-it/wait-for-it.sh http://localhost:4466 -t 30 -- ./run.sh
prisma:
image: prismagraphql/prisma:1.34
restart: always
networks:
net:
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
databases:
default:
connector: mongo
uri: mongodb://prisma:prisma@mongo
command: /bin/sh.sh
mongo:
image: mongo:3.6
restart: always
networks:
net:
environment:
MONGO_INITDB_ROOT_USERNAME: prisma
MONGO_INITDB_ROOT_PASSWORD: prisma
ports:
- "27017:27017"
volumes:
- mongo:/var/lib/mongo
volumes:
mongo:
networks:
net:
And this is the dockerfile of the web service:
FROM node:10
WORKDIR /app
COPY . /app/
RUN yarn install --pure-lockfile
RUN yarn global add prisma
And this is the run.sh file:
echo "prisma deploy command "
prisma deploy
echo "get-schema command"
yarn run get-schema
echo "starting command"
yarn run start
Are there anything that I misunderstand, Or what I need to fix to make it work?
Upvotes: 0
Views: 1921
Reputation: 69
Run your docker container by typing $docker-compose up -d -d flag is for running container in detach mode.
Instead of using endpoint as http://localhost:4466 use http://127.0.1.1:4466 Or check your localhost by the cmd: $localhost -i. In prisma-binding your constructor should have endpoint as http://127.0.1.1:4466.
const prisma = new Prisma({
typeDefs: './src/generated/prisma.graphql',
endpoint: 'http://127.0.1.1:4466'
});
Upvotes: 0
Reputation: 921
Change the content of your prisma.yml
from
endpoint: http://localhost:4466
datamodel: datamodel.prisma
to
endpoint: http://192.168.99.100:4466
datamodel: datamodel.prisma
This worked for me.
Upvotes: 0
Reputation: 2516
The localhost
in your Node application points to the container running Node itself, not your host machine. Replace http://localhost:4466
with http://prisma:4466
or http://<host-machine-local-ip>:4466
To get host IP on a Unix machine run:
hostname -i
Or
ifconfig | awk '/broadcast/ {print $2}'
Upvotes: 1
Reputation: 16910
You should use http://prisma:4466
as the connection URL in your web container. As your containers will be connected to the same network the name of the container will be DNS name and therefor will be resolved to IP of concrete container.
Upvotes: 1