最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

docker - Unable to connect redis from VPS server but can connect from other - Stack Overflow

programmeradmin0浏览0评论

I have a VPS with public IP, installed docker to use redis as external service here's my docker-compose file

version: '3'

services:
  api:
    build:
      context: .
      dockerfile: ./App.API/Dockerfile-API
    ports:
      - "3333:5000"
    restart: "unless-stopped"
    networks:
      - app-network
  # ........

  cache:
    container_name: cache
    image: redis:alpine
    ports:
      - "6379:6379"
    restart: "unless-stopped"
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

The api service is created by Dotnet as backend, needs to connect redis from same docker network (app-network)

But when I start the API, the api shows the logs

Unhandled exception. StackExchange.Redis.RedisConnectionException: The message timed out in the backlog attempting to send because no connection became available (5000ms) - Last Connection Exception: It was not possible to connect to the redis server(s). ConnectTimeout, command=GET, timeout: 5000, inst: 0, qu: 1, qs: 0, aw: False, bw: SpinningDown, rs: NotStarted, ws: Idle, in: 0, last-in: 0, cur-in: 0, sync-ops: 1, async-ops: 0, serverEndpoint: 103.186.65.94:6379, conn-sec: n/a, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: 676ed7d04882(SE.Redis-v2.7.27.49176), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=0,Free=32767,Min=4,Max=32767), POOL: (Threads=5,QueuedItems=0,CompletedItems=133,Timers=13), v: 2.7.27.49176 (Please take a look at this article for some common client-side issues that can cause timeouts: .Redis/Timeouts)
 ---> StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s). ConnectTimeout
   --- End of inner exception stack trace ---
   at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor`1 processor, ServerEndPoint server, T defaultValue) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 2105
......

The connection string in backend api service is cache:6379,password=,ssl=true,abortConnect=False

Looks like the api cannot connect to cache service althought they're in same network (app-network)

I tried to change connection string above to the VPS public IP address but it still doesn't work <ip-address>:6379,password=,ssl=true,abortConnect=False

But when I tried to run the api locally (run from my computer, in debug mode), with connection string contains the IP address above, then it works fine. I don't know how to fix this issue, and how do I need to correct this issue in VPS server (local environment works fine) That's my issue. Thanks everyone for your attention

发布评论

评论列表(0)

  1. 暂无评论