简体   繁体   中英

Prisma failed to connect localhost:4466 from another docker container

From yesterday i am trying to dockerize following things together for that i used docker-compose which contain's definations as follows:

docker.compose.yml

version: '3'
networks:
  network:
    driver: bridge
services:
  server:
    container_name: truckpeserver
    restart: always
    build: .
    networks:
      - network
    links:
      - redis
    ports:
      - '3000:3000'
  redis:
    container_name: "redisserver"
    image: redis:latest
    networks:
      - network
    restart: always
    command: ["redis-server", "--bind", "redis", "--port", "6379"]
  prisma:
    image: prismagraphql/prisma:1.34
    restart: always
    ports:
      - '4466:4466'
    networks:
      - network
    environment:
      PRISMA_ENDPOINT: http://prisma:4466/
      PRISMA_CONFIG: |
        port: 4466
        databases:
          default:
            connector: mysql
            host: mysql
            port: 3306
            user: root
            password: prisma
  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: prisma
    volumes:
      - mysql:/var/lib/mysql
volumes:
  mysql: ~

and dockerfile for running my graphql server which is as follows:

# install node.js
FROM node:10.15.3

# create necessary directories and
# permissions
RUN mkdir -p /home/node/truckpeserver/node_modules && chown -R node:node /home/node/truckpeserver

# switch to working directory
WORKDIR /home/node/truckpeserver

# copy package.json files in directory
COPY package*.json ./

# check and switch to node user.
USER node

# install node_modules.
RUN npm install

# remove duplicate packages
RUN npm dedupe

# copy project files.
COPY --chown=node:node . .

# build server
RUN npm run build

# start server
CMD ["npm", "start"]

Problem:

Everything work's fine except prisma. when every my executing code query prisma i got error as follow's:

Error

truckpeserver | FetchError: request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466
truckpeserver |     at ClientRequest.<anonymous> (/home/node/truckpeserver/node_modules/cross-fetch/node_modules/node-fetch/lib/index.js:1393:11)
truckpeserver |     at ClientRequest.emit (events.js:189:13)
truckpeserver |     at ClientRequest.EventEmitter.emit (domain.js:441:20)
truckpeserver |     at Socket.socketErrorListener (_http_client.js:392:9)
truckpeserver |     at Socket.emit (events.js:189:13)
truckpeserver |     at Socket.EventEmitter.emit (domain.js:441:20)
truckpeserver |     at emitErrorNT (internal/streams/destroy.js:82:8)
truckpeserver |     at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
truckpeserver |     at process._tickCallback (internal/process/next_tick.js:63:19)

What I have tried already.

  1. Linking
  2. Creating a network: bridge

Everything fails and prisma is not working please help

Remove linking any another configuration regarding network as docker-compose will take care of it. in service to service communication, you can use container name to do some call from one container to another.

Now the error is from your truckpeserver container,

truckpeserver | FetchError: request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466

all you need to change localhost to prisma:4466 . when you use localhost in some container it will point localhost of that container, you can not access other container using localhost.

From the error logs, it seems you are using cross-fetch? then you can try something like

fetch('//prisma:4466')
  .then(res => {
    if (res.status >= 400) {
      throw new Error("Bad response from server");
    }
    return res.json();
  })
....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM