efcore.pg: Cannot assign requested address (2.0.0-preview2-final)
When running on docker image (microsoft/aspnetcore-build:2) I get Unhandled Exception: System.Net.Sockets.SocketException: Cannot assign requested address
It worked before update to 2.0 and it works now on Windows dev machine.
Projects are .NET Core 2.0 & .NET Standard 2.0.
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0-preview2-final" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="2.0.0-preview1" />
Stacktrace:
Unhandled Exception: System.Net.Sockets.SocketException: Cannot assign requested address at System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state) at System.Net.Sockets.Socket.UnsafeBeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state, Boolean flowContext) at System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state) at System.Threading.Tasks.TaskFactory1.FromAsyncImpl[TArg1](Func4 beginMethod, Func2 endFunction, Action1 endAction, TArg1 arg1, Object state, TaskCreationOptions creationOptions) at Npgsql.NpgsqlConnector.<ConnectAsync>d__141.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Npgsql.NpgsqlConnector.<RawOpen>d__139.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Npgsql.NpgsqlConnector.<Open>d__136.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Npgsql.NpgsqlConnection.<Open>d__28.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Npgsql.NpgsqlConnection.<>c__DisplayClass26_0.<<OpenAsync>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.EntityFrameworkCore.Storage.Internal.NpgsqlDatabaseCreator.<ExistsAsync>d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.<EnsureDeletedAsync>d__16.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at EkoLab.Domain.Commands.SetupDatabaseCommand.SetupDatabaseCommandHandler.<HandleAsync>d__5.MoveNext() in /app/server/EkoLab.Domain/Commands/SetupDatabaseCommand.cs:line 54
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at EkoLab.Decorators.ValidateAsyncCommandDecorator1.<HandleAsync>d__3.MoveNext() in /app/server/EkoLab/Decorators/ValidateAsyncCommandDecorator.cs:line 36 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at EkoLab.Decorators.LogAsyncCommandDecorator1.<HandleAsync>d__4.MoveNext() in /app/server/EkoLab/Decorators/LogAsyncCommandDecorator.cs:line 39
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at EkoLab.Startup.<InitializeContainer>d__7.MoveNext() in /app/server/EkoLab/Startup.cs:line 165
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadPoolWorkQueue.Dispatch()`
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (2 by maintainers)
@cime I was having the same issue as you originally. I was trying to use a connection string that had localhost in it but running in docker compose. When compose boots up all the containers, localhost isn’t valid because they’re in a docker network. I just had to change the hostname of the connection string to whatever the name of your postgres service is in your docker compose file.
This is a feature of docker compose which automatically configures a network between the containers and routes the hostname for you.
Solution for me was simply using
host.docker.internalinstead oflocalhostin your connection string (this is only supported on Docker for Windows and Mac, but not on Linux).For me the same issue was fixed by using the Gateway address of the database Docker container.
Note: I do not have the db listed in my docker-compose.yml. Instead I start it separately in the background using a different docker-compose file.
I was having no end of issues trying to get my API working. Hero.
hey buddy you save my life