我正在尝试在Docker上运行ASP.NET Core 2.0应用程序(REDIS
+ RabbitMQ
+ NGINX
)。
当我通过docker-compose
上传这些容器时,这些服务可以运行,甚至可以由Windows访问,因为它们由" HostPORT:ContainerPORT"映射。
但是,在测试应用程序本身时,.NET会在控制台中通知您无法连接到REDIS,例如。
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLDGDJNAEB9E", Request id "0HLDGDJNAEB9E:00000001": An unhandled exception was thrown by the application.
StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING.
我的docker-compose.yml:
version: '3'
services:
nginx:
build:
dockerfile: ./nginx/nginx.dockerfile
context: .
image: nginx
container_name: nginx
ports:
- "80:80"
networks:
- production-network
depends_on:
- "wordSearcherApp"
wordSearcherApp:
image: wordsearcherapplication
container_name: wordsearcherapp
build:
context: .
dockerfile: WordSearcher/Dockerfile
networks:
- production-network
ports:
- "61370"
volumes:
- repository:/repository
depends_on:
- redis
- rabbit
redis:
image: redis
container_name: redis
ports:
- "6379:6379"
networks:
- production-network
rabbit:
image: rabbitmq
container_name: rabbitmq
ports:
- "5672:5672"
- "15672:15672"
networks:
- production-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:15672"]
interval: 30s
timeout: 10s
retries: 5
networks:
production-network:
driver: bridge
volumes:
repository:
driver: local
对于C#中的Connection,我使用此connectionString localhost:6379
我该怎么做? 感谢。
答案 0 :(得分:0)
使用redis:6379
代替localhost:6379
。
Docker-Compose将使用您为docker-compose.yml文件中的服务定义的名称作为其容器的主机名。