gpt4 book ai didi

docker - .Net Core与Docker的EC2教程问题

转载 作者:行者123 更新时间:2023-12-02 20:16:29 24 4
gpt4 key购买 nike

我正在研究this教程,并尝试在EC2容器服务上安装一个简单的ASP.Net核心应用程序。我快要结束了,但是无法启动我的容器。当我输入:

docker run 171329494690.dkr.ecr.us-west-2.amazonaws.com/ecsdemo-redisgeo:latest

手动运行容器时,出现以下错误:
    Project RedisGeo.ServiceModel (.NETStandard,Version=v1.6) was previously compiled. Skipping compilation.
Project RedisGeo.ServiceInterface (.NETStandard,Version=v1.6) was previously compiled. Skipping compilation.
Project RedisGeo (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
fail: ServiceStack.Redis.RedisNativeClient[0]
Could not connect to redis Instance at localhost:6379
fail: ServiceStack.Redis.RedisNativeClient[0]
Could not connect to redis Instance at localhost:6379
fail: ServiceStack.Redis.RedisNativeClient[0]
localhost:6379

Unhandled Exception: ServiceStack.Redis.RedisException: localhost:6379 ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: Connection refused 127.0.0.1:6379
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
at System.Net.Sockets.Socket.Connect(IPAddress address, Int32 port)
at ServiceStack.Redis.RedisNativeClient.Connect() in /opt/lib/teamcity-agent/work/8dcfdcec54d0f21a/src/ServiceStack.Redis/RedisNativeClient_Utils.cs:line 212
at ServiceStack.Redis.RedisNativeClient.AssertConnectedSocket() in /opt/lib/teamcity-agent/work/8dcfdcec54d0f21a/src/ServiceStack.Redis/RedisNativeClient_Utils.cs:line 257
--- End of inner exception stack trace ---
at ServiceStack.Redis.RedisNativeClient.AssertConnectedSocket() in /opt/lib/teamcity-agent/work/8dcfdcec54d0f21a/src/ServiceStack.Redis/RedisNativeClient_Utils.cs:line 273
at ServiceStack.Redis.RedisNativeClient.AssertServerVersionNumber() in /opt/lib/teamcity-agent/work/8dcfdcec54d0f21a/src/ServiceStack.Redis/RedisNativeClient_Utils.cs:line 47
at ServiceStack.Redis.RedisClient.GetServerRole() in /opt/lib/teamcity-agent/work/8dcfdcec54d0f21a/src/ServiceStack.Redis/RedisClient.cs:line 1092
at ServiceStack.Redis.RedisResolver.CreateRedisClient(RedisEndpoint config, Boolean master) in /opt/lib/teamcity-agent/work/8dcfdcec54d0f21a/src/ServiceStack.Redis/RedisResolver.cs:line 84
at ServiceStack.Redis.RedisManagerPool.GetClient() in /opt/lib/teamcity-agent/work/8dcfdcec54d0f21a/src/ServiceStack.Redis/RedisManagerPool.cs:line 194
at RedisGeo.AppHost.ImportCountry(IRedisClientsManager redisManager, String countryCode) in /app/RedisGeo/AppHost.cs:line 35
at RedisGeo.AppHost.Configure(Container container) in /app/RedisGeo/AppHost.cs:line 30
at ServiceStack.ServiceStackHost.Init() in /opt/lib/teamcity-agent/work/d09206570215629/src/ServiceStack/ServiceStackHost.cs:line 189
at ServiceStack.NetCoreAppHostExtensions.UseServiceStack(IApplicationBuilder app, AppHostBase appHost) in /opt/lib/teamcity-agent/work/d09206570215629/src/ServiceStack/AppHostBase.NetCore.cs:line 178
at RedisGeo.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in /app/RedisGeo/Startup.cs:line 27
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at RedisGeo.Program.Main(String[] args) in /app/RedisGeo/Program.cs:line 14

我们将不胜感激,因为我是AWS的新手,所以请告知我是否可以提供更多信息。

这是我的docker文件:
FROM microsoft/dotnet:1.1-sdk-projectjson
COPY src /app
WORKDIR /app
RUN ["dotnet", "restore"]
WORKDIR /app/RedisGeo
RUN ["dotnet", "build"]
EXPOSE 5000/tcp
ENV ASPNETCORE_URLS https://*:5000
ENTRYPOINT ["dotnet", "run", "--server.urls", "http://*:5000"]

当我运行以下命令 docker ps --format "{{.ID}}: {{.Status}} {{.Command}} {{.Ports}}"时,我得到以下当前正在运行的Docker容器的输出
8285b5479401: Up 22 hours "/agent"
ba110a5f14ef: Up 46 hours "/app/docker-entrypoi" 0.0.0.0:80->80/tcp, 443/tcp

ecsdemo-redisgeo任务容器定义

enter image description here

enter image description here

最佳答案

Connection refused 127.0.0.1:6379

此错误表明 127.0.0.1:6379上没有可用的Redis Server实例。

确保您的task-definition.json与 ECS task-definition.json相同,其中包括 ${IMAGE_NAME}-redis容器定义,该定义将告诉ECS也将Redis服务器Docker实例与您的App一起部署。您可以在 redis-geo/scripts上找到用于部署redis-geo App的脚本。

可从 REDIS_HOST Environment Variable访问redis服务器实例的主机名,如果存在,则应使用 use in your App进行访问,例如:
container.Register<IRedisClientsManager>(c =>
new RedisManagerPool(AppSettings.Get("REDIS_HOST", defaultValue:"localhost")));

关于docker - .Net Core与Docker的EC2教程问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42407211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com