I am trying to dockerize an app and I have an issue with Postgresql docker container. I am getting this error:
Npgsql.PostgresException (0x80004005): 42P01: relation "Users" does not exist
Here is my docker-compose.yml file:
version: '3.4'
networks:
dating-network:
driver: bridge
services:
datingappapi:
image: datingappapi
build:
context: .
dockerfile: DatingApp.API/Dockerfile
ports:
- "8000:80"
environment:
- "ConnectionStrings:PostgresConnection=User ID=postgres;Password=password;Server=postgres-image;Port=5432;Database=petdating;Integrated Security=true;Pooling=true;"
depends_on:
- postgres-image
networks:
- dating-network
postgres-image:
image: postgres
container_name: datingapp_postgress-image_1
ports:
- "5432:5432"
restart: always
environment:
# POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "password"
POSTGRES_DB: "petdating"
networks:
- dating-network
And here is the stack trace from the Docker logs:
Attaching to datingapp_datingappapi_1, datingapp_postgress-image_1
datingappapi_1 | warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
datingappapi_1 | Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
datingappapi_1 | info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
datingappapi_1 | User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
datingappapi_1 | info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58]
datingappapi_1 | Creating key {453d663b-80a9-4136-97a4-6ad9b66d0c03} with creation date 2020-11-28 11:51:57Z, activation date 2020-11-28 11:51:57Z, and expiration date 2021-02-26 11:51:57Z.
datingappapi_1 | warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
datingappapi_1 | No XML encryptor configured. Key {453d663b-80a9-4136-97a4-6ad9b66d0c03} may be persisted to storage in unencrypted form.
datingappapi_1 | info: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[39]
datingappapi_1 | Writing data to file '/root/.aspnet/DataProtection-Keys/key-453d663b-80a9-4136-97a4-6ad9b66d0c03.xml'.
datingappapi_1 | info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
datingappapi_1 | Entity Framework Core 3.1.9 initialized 'DataContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: None
datingappapi_1 | fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
datingappapi_1 | Failed executing DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
datingappapi_1 | SELECT EXISTS (
datingappapi_1 | SELECT 1
datingappapi_1 | FROM "Users" AS u)
datingappapi_1 | fail: Microsoft.EntityFrameworkCore.Query[10100]
datingappapi_1 | An exception occurred while iterating over the results of a query for context type 'DatingApp.API.Models.Data.DataContext'.
datingappapi_1 | Npgsql.PostgresException (0x80004005): 42P01: relation "Users" does not exist
datingappapi_1 | at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
datingappapi_1 | --- End of stack trace from previous location where exception was thrown ---
datingappapi_1 | at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
datingappapi_1 | --- End of stack trace from previous location where exception was thrown ---
datingappapi_1 | at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
datingappapi_1 | at Npgsql.NpgsqlDataReader.NextResult()
datingappapi_1 | at Npgsql.NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
datingappapi_1 | at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior)
datingappapi_1 | at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
datingappapi_1 | at System.Data.Common.DbCommand.ExecuteReader()
datingappapi_1 | at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
datingappapi_1 | at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
datingappapi_1 | at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
datingappapi_1 | at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
datingappapi_1 | Exception data:
datingappapi_1 | Severity: ERROR
datingappapi_1 | SqlState: 42P01
datingappapi_1 | MessageText: relation "Users" does not exist
datingappapi_1 | Position: 39
datingappapi_1 | File: parse_relation.c
datingappapi_1 | Line: 1379
datingappapi_1 | Routine: parserOpenTable
datingappapi_1 | Npgsql.PostgresException (0x80004005): 42P01: relation "Users" does not exist
datingappapi_1 | at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
datingappapi_1 | --- End of stack trace from previous location where exception was thrown ---
datingappapi_1 | at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
datingappapi_1 | --- End of stack trace from previous location where exception was thrown ---
datingappapi_1 | at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
datingappapi_1 | at Npgsql.NpgsqlDataReader.NextResult()
datingappapi_1 | at Npgsql.NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
datingappapi_1 | at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior)
datingappapi_1 | at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
datingappapi_1 | at System.Data.Common.DbCommand.ExecuteReader()
datingappapi_1 | at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
datingappapi_1 | at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
datingappapi_1 | at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
datingappapi_1 | at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
datingappapi_1 | Exception data:
datingappapi_1 | Severity: ERROR
datingappapi_1 | SqlState: 42P01
datingappapi_1 | MessageText: relation "Users" does not exist
datingappapi_1 | Position: 39
datingappapi_1 | File: parse_relation.c
datingappapi_1 | Line: 1379
datingappapi_1 | Routine: parserOpenTable
datingappapi_1 | crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
datingappapi_1 | Application startup exception
datingappapi_1 | Npgsql.PostgresException (0x80004005): 42P01: relation "Users" does not exist
datingappapi_1 | at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
datingappapi_1 | --- End of stack trace from previous location where exception was thrown ---
datingappapi_1 | at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
datingappapi_1 | --- End of stack trace from previous location where exception was thrown ---
datingappapi_1 | at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
datingappapi_1 | at Npgsql.NpgsqlDataReader.NextResult()
datingappapi_1 | at Npgsql.NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
datingappapi_1 | at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior)
datingappapi_1 | at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
datingappapi_1 | at System.Data.Common.DbCommand.ExecuteReader()
datingappapi_1 | at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
datingappapi_1 | at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
datingappapi_1 | at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
datingappapi_1 | at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
datingappapi_1 | at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
datingappapi_1 | at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
datingappapi_1 | at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
datingappapi_1 | at System.Linq.Queryable.Any[TSource](IQueryable`1 source)
datingappapi_1 | at DatingApp.API.Models.Data.SeedData.SeedUsers() in /src/DatingApp.API/Models/Data/SeedData.cs:line 19
datingappapi_1 | at DatingApp.API.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env, SeedData seeder) in /src/DatingApp.API/Startup.cs:line 120
datingappapi_1 | at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
datingappapi_1 | at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
datingappapi_1 | at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
datingappapi_1 | at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
datingappapi_1 | at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__2(IApplicationBuilder app)
datingappapi_1 | at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
datingappapi_1 | at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
datingappapi_1 | at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
datingappapi_1 | Exception data:
datingappapi_1 | Severity: ERROR
datingappapi_1 | SqlState: 42P01
datingappapi_1 | MessageText: relation "Users" does not exist
datingappapi_1 | Position: 39
datingappapi_1 | File: parse_relation.c
datingappapi_1 | Line: 1379
datingappapi_1 | Routine: parserOpenTable
datingappapi_1 | Unhandled exception. Npgsql.PostgresException (0x80004005): 42P01: relation "Users" does not exist
datingappapi_1 | at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
datingappapi_1 | --- End of stack trace from previous location where exception was thrown ---
datingappapi_1 | at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
datingappapi_1 | --- End of stack trace from previous location where exception was thrown ---
datingappapi_1 | at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
datingappapi_1 | at Npgsql.NpgsqlDataReader.NextResult()
datingappapi_1 | at Npgsql.NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
datingappapi_1 | at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior)
datingappapi_1 | at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
datingappapi_1 | at System.Data.Common.DbCommand.ExecuteReader()
datingappapi_1 | at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
datingappapi_1 | at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
datingappapi_1 | at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
datingappapi_1 | at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
datingappapi_1 | at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
datingappapi_1 | at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
datingappapi_1 | at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
datingappapi_1 | at System.Linq.Queryable.Any[TSource](IQueryable`1 source)
datingappapi_1 | at DatingApp.API.Models.Data.SeedData.SeedUsers() in /src/DatingApp.API/Models/Data/SeedData.cs:line 19
datingappapi_1 | at DatingApp.API.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env, SeedData seeder) in /src/DatingApp.API/Startup.cs:line 120
datingappapi_1 | at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
datingappapi_1 | at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
datingappapi_1 | at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
datingappapi_1 | at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
datingappapi_1 | at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__2(IApplicationBuilder app)
datingappapi_1 | at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
datingappapi_1 | at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
datingappapi_1 | at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
datingappapi_1 | at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
datingappapi_1 | at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
datingappapi_1 | at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
datingappapi_1 | at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
datingappapi_1 | at DatingApp.API.Program.Main(String[] args) in /src/DatingApp.API/Program.cs:line 17
datingappapi_1 | Exception data:
datingappapi_1 | Severity: ERROR
datingappapi_1 | SqlState: 42P01
datingappapi_1 | MessageText: relation "Users" does not exist
datingappapi_1 | Position: 39
datingappapi_1 | File: parse_relation.c
datingappapi_1 | Line: 1379
datingappapi_1 | Routine: parserOpenTable
datingapp_postgress-image_1 | The files belonging to this database system will be owned by user "postgres".
datingapp_postgress-image_1 | This user must also own the server process.
datingapp_postgress-image_1 |
datingapp_postgress-image_1 | The database cluster will be initialized with locale "en_US.utf8".
datingapp_postgress-image_1 | The default database encoding has accordingly been set to "UTF8".
datingapp_postgress-image_1 | The default text search configuration will be set to "english".
datingapp_postgress-image_1 |
datingapp_postgress-image_1 | Data page checksums are disabled.
datingapp_postgress-image_1 |
datingapp_postgress-image_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
datingapp_postgress-image_1 | creating subdirectories ... ok
datingapp_postgress-image_1 | selecting dynamic shared memory implementation ... posix
datingapp_postgress-image_1 | selecting default max_connections ... 100
datingapp_postgress-image_1 | selecting default shared_buffers ... 128MB
datingapp_postgress-image_1 | selecting default time zone ... Etc/UTC
datingapp_postgress-image_1 | creating configuration files ... ok
datingapp_postgress-image_1 | running bootstrap script ... ok
datingapp_postgress-image_1 | performing post-bootstrap initialization ... ok
datingapp_postgress-image_1 | syncing data to disk ... ok
datingapp_postgress-image_1 |
datingapp_postgress-image_1 |
datingapp_postgress-image_1 | Success. You can now start the database server using:
datingapp_postgress-image_1 |
datingapp_postgress-image_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
datingapp_postgress-image_1 |
datingapp_postgress-image_1 | initdb: warning: enabling "trust" authentication for local connections
datingapp_postgress-image_1 | You can change this by editing pg_hba.conf or using the option -A, or
datingapp_postgress-image_1 | --auth-local and --auth-host, the next time you run initdb.
datingapp_postgress-image_1 | waiting for server to start....2020-11-28 11:51:57.543 UTC [46] LOG: starting PostgreSQL 13.1 (Debian 13.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
datingapp_postgress-image_1 | 2020-11-28 11:51:57.545 UTC [46] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
datingapp_postgress-image_1 | 2020-11-28 11:51:57.550 UTC [47] LOG: database system was shut down at 2020-11-28 11:51:57 UTC
datingapp_postgress-image_1 | 2020-11-28 11:51:57.553 UTC [46] LOG: database system is ready to accept connections
datingapp_postgress-image_1 | done
datingapp_postgress-image_1 | server started
datingapp_postgress-image_1 | CREATE DATABASE
datingapp_postgress-image_1 |
datingapp_postgress-image_1 |
datingapp_postgress-image_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
datingapp_postgress-image_1 |
datingapp_postgress-image_1 | 2020-11-28 11:51:57.741 UTC [46] LOG: received fast shutdown request
datingapp_postgress-image_1 | waiting for server to shut down....2020-11-28 11:51:57.743 UTC [46] LOG: aborting any active transactions
datingapp_postgress-image_1 | 2020-11-28 11:51:57.744 UTC [46] LOG: background worker "logical replication launcher" (PID 53) exited with exit code 1
datingapp_postgress-image_1 | 2020-11-28 11:51:57.744 UTC [48] LOG: shutting down
datingapp_postgress-image_1 | 2020-11-28 11:51:57.756 UTC [46] LOG: database system is shut down
datingapp_postgress-image_1 | done
datingapp_postgress-image_1 | server stopped
datingapp_postgress-image_1 |
datingapp_postgress-image_1 | PostgreSQL init process complete; ready for start up.
datingapp_postgress-image_1 |
datingapp_postgress-image_1 | 2020-11-28 11:51:57.857 UTC [1] LOG: starting PostgreSQL 13.1 (Debian 13.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
datingapp_postgress-image_1 | 2020-11-28 11:51:57.857 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
datingapp_postgress-image_1 | 2020-11-28 11:51:57.857 UTC [1] LOG: listening on IPv6 address "::", port 5432
datingapp_postgress-image_1 | 2020-11-28 11:51:57.862 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
datingapp_postgress-image_1 | 2020-11-28 11:51:57.867 UTC [64] LOG: database system was shut down at 2020-11-28 11:51:57 UTC
datingapp_postgress-image_1 | 2020-11-28 11:51:57.871 UTC [1] LOG: database system is ready to accept connections
datingapp_postgress-image_1 | 2020-11-28 11:51:58.326 UTC [71] ERROR: relation "Users" does not exist at character 39
datingapp_postgress-image_1 | 2020-11-28 11:51:58.326 UTC [71] STATEMENT: SELECT EXISTS (
datingapp_postgress-image_1 | SELECT 1
datingapp_postgress-image_1 | FROM "Users" AS u)
datingapp_datingappapi_1 exited with code 139
Any help is appreciated. Thanks.
User contributions licensed under CC BY-SA 3.0