Open tojosmarce opened 3 years ago
Hey, what problem do you have?
I have these sentences in docker-compose:
_...
But I get this error:
SocketException: Connection refused Npgsql.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
Database server have no been found. When I write for server within connectionstring the IP address directly, it works.
I have same problem.
This is my yml
version: '3.4'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx
ports:
- '80:80'
- '443:443'
volumes:
- '/var/run/docker.sock:/tmp/docker.sock:ro'
- './shared/nginx/vhost.d:/etc/nginx/vhost.d'
- './shared/nginx/certs:/etc/nginx/certs:ro'
networks:
proxy: null
identityserverui:
aliases:
- sts.skoruba.local
- admin.skoruba.local
- admin-api.skoruba.local
restart: always
skoruba.identityserver4.admin:
image: '${DOCKER_REGISTRY-}skoruba-identityserver4-admin'
build:
context: .
dockerfile: src/Skoruba.IdentityServer4.Admin/Dockerfile
container_name: skoruba-identityserver4-admin
environment:
- VIRTUAL_HOST=admin.skoruba.local
- 'ConnectionStrings__ConfigurationDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__PersistedGrantDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__IdentityDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__AdminLogDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__AdminAuditLogDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__DataProtectionDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'AdminConfiguration__IdentityAdminBaseUrl=https://admin.skoruba.local'
- 'AdminConfiguration__IdentityAdminRedirectUri=https://admin.skoruba.local/signin-oidc'
- 'AdminConfiguration__IdentityServerBaseUrl=https://sts.skoruba.local'
- AdminConfiguration__RequireHttpsMetadata=false
- 'IdentityServerData__Clients__0__ClientUri=https://admin.skoruba.local'
- 'IdentityServerData__Clients__0__RedirectUris__0=https://admin.skoruba.local/signin-oidc'
- 'IdentityServerData__Clients__0__FrontChannelLogoutUri=https://admin.skoruba.local/signin-oidc'
- 'IdentityServerData__Clients__0__PostLogoutRedirectUris__0=https://admin.skoruba.local/signout-callback-oidc'
- 'IdentityServerData__Clients__0__AllowedCorsOrigins__0=https://admin.skoruba.local'
- 'IdentityServerData__Clients__1__RedirectUris__0=https://admin-api.skoruba.local/swagger/oauth2-redirect.html'
- 'Serilog__WriteTo__1__Args__connectionString=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'DatabaseProviderConfiguration__ProviderType=PostgreSQL'
- DockerConfiguration__UpdateCaCertificate=true
- ASPNETCORE_ENVIRONMENT=Development
command: dotnet Skoruba.IdentityServer4.Admin.dll /seed
depends_on:
- db
- skoruba.identityserver4.sts.identity
volumes:
- './shared/serilog.json:/app/serilog.json'
- './shared/identitydata.json:/app/identitydata.json'
- './shared/identityserverdata.json:/app/identityserverdata.json'
- './shared/nginx/certs/cacerts.crt:/usr/local/share/ca-certificates/cacerts.crt'
networks:
identityserverui: null
skoruba.identityserver4.admin.api:
image: '${DOCKER_REGISTRY-}skoruba-identityserver4-admin-api'
build:
context: .
dockerfile: src/Skoruba.IdentityServer4.Admin.Api/Dockerfile
container_name: skoruba-identityserver4-admin-api
environment:
- VIRTUAL_HOST=admin-api.skoruba.local
- AdminApiConfiguration__RequireHttpsMetadata=false
- 'AdminApiConfiguration__ApiBaseUrl=https://admin-api.skoruba.local'
- 'AdminApiConfiguration__IdentityServerBaseUrl=https://sts.skoruba.local'
- 'ConnectionStrings__ConfigurationDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__PersistedGrantDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__IdentityDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__AdminLogDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__AdminAuditLogDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__DataProtectionDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'DatabaseProviderConfiguration__ProviderType=PostgreSQL'
- DockerConfiguration__UpdateCaCertificate=true
- ASPNETCORE_ENVIRONMENT=Development
volumes:
- './shared/serilog.json:/app/serilog.json'
- './shared/nginx/certs/cacerts.crt:/usr/local/share/ca-certificates/cacerts.crt'
networks:
identityserverui: null
skoruba.identityserver4.sts.identity:
image: '${DOCKER_REGISTRY-}skoruba-identityserver4-sts-identity'
build:
context: .
dockerfile: src/Skoruba.IdentityServer4.STS.Identity/Dockerfile
container_name: skoruba-identityserver4-sts-identity
environment:
- VIRTUAL_HOST=sts.skoruba.local
- 'ConnectionStrings__ConfigurationDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__PersistedGrantDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__IdentityDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'ConnectionStrings__DataProtectionDbConnection=Server=localhost; User Id=postgres; Database=is4admin; Port=5432; Password=postgres; SSL Mode=Prefer; Trust Server Certificate=true'
- 'AdminConfiguration__IdentityAdminBaseUrl=https://admin.skoruba.local'
- 'AdminConfiguration__PageTitle=imPlatform'
- 'AdminConfiguration__HomePageLogoUri=~/images/maltese.png'
- 'AdminConfiguration__Theme=darkly'
- 'AdvancedConfiguration__PublicOrigin=https://sts.skoruba.local'
- 'AdvancedConfiguration__IssuerUri=https://sts.skoruba.local'
- 'DatabaseProviderConfiguration__ProviderType=PostgreSQL'
- DockerConfiguration__UpdateCaCertificate=true
- ASPNETCORE_ENVIRONMENT=Development
depends_on:
- db
volumes:
- './shared/serilog.json:/app/serilog.json'
- './shared/nginx/certs/cacerts.crt:/usr/local/share/ca-certificates/cacerts.crt'
networks:
identityserverui:
aliases:
- sts.skoruba.local
db:
image: 'postgres'
ports:
- '7900:5432'
container_name: skoruba-identityserver4-db
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- dbdata:/var/lib/postgresql/data
networks:
identityserverui: null
volumes:
dbdata:
driver: local
networks:
proxy:
driver: bridge
identityserverui:
driver: bridge
and then skoruba-identityserver4-admin's log
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 3.1.6 initialized 'IdentityServerConfigurationDbContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.PostgreSQL
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 3.1.6 initialized 'IdentityServerPersistedGrantDbContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.PostgreSQL
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 3.1.6 initialized 'AdminIdentityDbContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.PostgreSQL
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 3.1.6 initialized 'AdminLogDbContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.PostgreSQL
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 3.1.6 initialized 'AdminAuditLogDbContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.PostgreSQL
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 3.1.6 initialized 'IdentityServerDataProtectionDbContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.PostgreSQL
[2021-06-07T13:04:10.5126531+00:00][INFO][1][Microsoft.EntityFrameworkCore.Infrastructure] Entity Framework Core "3.1.6" initialized '"IdentityServerPersistedGrantDbContext"' using provider '"Npgsql.EntityFrameworkCore.PostgreSQL"' with options: "MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.PostgreSQL "
[2021-06-07T13:04:10.6567161+00:00][FATL][12][] Host terminated unexpectedly
Npgsql.NpgsqlException (0x80004005): Exception while connecting
---> System.Net.Sockets.SocketException (99): 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.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP)
at Npgsql.NpgsqlConnector.ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnector.ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.ExistsAsync(CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.ExistsAsync(CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken)
at Skoruba.IdentityServer4.Admin.Helpers.DbMigrationHelpers.EnsureDatabasesMigratedAsync[TIdentityDbContext,TConfigurationDbContext,TPersistedGrantDbContext,TLogDbContext,TAuditLogDbContext,TDataProtectionDbContext](IServiceProvider services) in /src/src/Skoruba.IdentityServer4.Admin/Helpers/DbMigrationHelpers.cs:line 72
at Skoruba.IdentityServer4.Admin.Helpers.DbMigrationHelpers.ApplyDbMigrationsWithDataSeedAsync[TIdentityServerDbContext,TIdentityDbContext,TPersistedGrantDbContext,TLogDbContext,TAuditLogDbContext,TDataProtectionDbContext,TUser,TRole](IHost host, Boolean applyDbMigrationWithDataSeedFromProgramArguments, SeedConfiguration seedConfiguration, DatabaseMigrationsConfiguration databaseMigrationsConfiguration) in /src/src/Skoruba.IdentityServer4.Admin/Helpers/DbMigrationHelpers.cs:line 52
at Skoruba.IdentityServer4.Admin.Program.ApplyDbMigrationsWithDataSeedAsync(String[] args, IConfiguration configuration, IHost host) in /src/src/Skoruba.IdentityServer4.Admin/Program.cs:line 62
at Skoruba.IdentityServer4.Admin.Program.Main(String[] args) in /src/src/Skoruba.IdentityServer4.Admin/Program.cs:line 41
Hi,
I use postgres in my setup, but i have some differences. First, the connectionstring-format that I use is this one:
User ID=root;Password=myPassword;Host=localhost;Port=5432;Database=myDataBase;Pooling=true;Min Pool Size=0;Max Pool Size=100;Connection Lifetime=0
Also, and I can be wrong here, I'm not sure you can call the Host/Server localhost, as it will point att your local machine. Instead, the Host should be the name of the service/container. In your part just "db"
Hi,
I have some problems using PostgreSQL, can anyone help me with docker-compose.ylm using PostgreSQL database?
Thanks for your help.