docker compose redis连接问题

5t7ly7z5  于 2021-06-08  发布在  Redis
关注(0)|答案(1)|浏览(475)

我一直在尝试对接一个api。但redis崩溃了。nodejs和mongodb工作。
docker-compose.yaml文件

version: '3'
services:

  mongo:
    container_name: mongo
    image: mongo
    networks:
      - webnet
    ports:
      - '27017:27017'
  redis: 
    image: redis
    container_name: redis
    command: ["redis-server","--bind","redis","--port","6379"]
    ports:
      - '6379:6379'
    hostname: redis

  app:
    container_name: password-manager-docker
    restart: always
    build: .
    networks:
      - webnet
    ports:
      - '80:5000'
    links: 
      - mongo
      - redis
    environment: 
      MONGODB_URI: ${MONGODB_URI}
      clientID: ${clientID}
      clientSecret : ${clientSecret}
      PORT: ${PORT}
      NODE_ENV : ${NODE_ENV}
      JWT_SECRET_KEY: ${JWT_SECRET_KEY}
      JWT_EXPIRE: ${JWT_EXPIRE}
      REFRESH_TOKEN: ${REFRESH_TOKEN}
      JWT_REFRESH_SECRET_KEY: ${JWT_REFRESH_SECRET_KEY}
      JWT_REFRESH_EXPIRE: ${JWT_REFRESH_EXPIRE}
      JWT_COOKIE: ${JWT_COOKIE}

networks:
  webnet:

docker文件

FROM node:latest

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install 

COPY . .

EXPOSE 5000

CMD ["npm","start"]

错误是redis连接到127.0.0.1:6379失败-连接到127.0.0.1:6379。我怎样才能解决这个问题?

jc3wubiy

jc3wubiy1#

默认情况下,compose文件中的所有容器都将加入一个默认网络,在该网络中它们可以相互通信,但如果指定一个网络,则必须为所有容器指定该网络。因此,您可以从app和mongo服务中删除network声明,也可以在redis服务中指定它。

相关问题