✅ Cant create an image of postgres

appsettings
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",

"MyOptions": {
"JWT_ISSUER": "https://localhost:7261",
"SECRET_KEY": "my-32-character-ultra-secure-and-ultra-long-secret-AAAultra-long-secret-AAA"
},

"ConnectionStrings": {
"DefaultConnection": "Server=postgres;Port=5432;Database=projectservdb;Username=postgres;Password=root"
},

"ApiKey" : "key"
}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",

"MyOptions": {
"JWT_ISSUER": "https://localhost:7261",
"SECRET_KEY": "my-32-character-ultra-secure-and-ultra-long-secret-AAAultra-long-secret-AAA"
},

"ConnectionStrings": {
"DefaultConnection": "Server=postgres;Port=5432;Database=projectservdb;Username=postgres;Password=root"
},

"ApiKey" : "key"
}
54 Replies
blueberriesiftheywerecats
docker-compose
networks:
projectserv-net:
driver: bridge

services:
app:
container_name: projectserv
build:
context: .
dockerfile: Dockerfile
ports:
- "80:80"
depends_on:
- postgres
networks:
projectserv-net:
postgres:
container_name: postgres
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: root
POSTGRES_DB: projectservdb
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
projectserv-net:
volumes:
postgres-data:

networks:
projectserv-net:
driver: bridge

services:
app:
container_name: projectserv
build:
context: .
dockerfile: Dockerfile
ports:
- "80:80"
depends_on:
- postgres
networks:
projectserv-net:
postgres:
container_name: postgres
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: root
POSTGRES_DB: projectservdb
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
projectserv-net:
volumes:
postgres-data:

blueberriesiftheywerecats
building log
blueberriesiftheywerecats
Name or service not known dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["ProjectServ.WebApi/ProjectServ.WebApi.csproj", "ProjectServ.WebApi/"]
COPY ["ProjectServ.Application/ProjectServ.Application.csproj", "ProjectServ.Application/"]
COPY ["ProjectServ.Domain/ProjectServ.Domain.csproj", "ProjectServ.Domain/"]
COPY ["ProjectServ.Infrastructure/ProjectServ.Infrastructure.csproj", "ProjectServ.Infrastructure/"]

RUN dotnet restore "ProjectServ.WebApi/ProjectServ.WebApi.csproj"
COPY . .
WORKDIR "/src/ProjectServ.WebApi"
RUN dotnet build "ProjectServ.WebApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ProjectServ.WebApi.csproj" -c Release -o /app/publish /p:UseAppHost=false

RUN dotnet tool install --global dotnet-ef --version 7.0.13
ENV PATH="${PATH}:/root/.dotnet/tools"
RUN dotnet ef database update

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ProjectServ.WebApi.dll"]
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["ProjectServ.WebApi/ProjectServ.WebApi.csproj", "ProjectServ.WebApi/"]
COPY ["ProjectServ.Application/ProjectServ.Application.csproj", "ProjectServ.Application/"]
COPY ["ProjectServ.Domain/ProjectServ.Domain.csproj", "ProjectServ.Domain/"]
COPY ["ProjectServ.Infrastructure/ProjectServ.Infrastructure.csproj", "ProjectServ.Infrastructure/"]

RUN dotnet restore "ProjectServ.WebApi/ProjectServ.WebApi.csproj"
COPY . .
WORKDIR "/src/ProjectServ.WebApi"
RUN dotnet build "ProjectServ.WebApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ProjectServ.WebApi.csproj" -c Release -o /app/publish /p:UseAppHost=false

RUN dotnet tool install --global dotnet-ef --version 7.0.13
ENV PATH="${PATH}:/root/.dotnet/tools"
RUN dotnet ef database update

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ProjectServ.WebApi.dll"]
cap5lut
cap5lut12mo ago
i think u specified the network wrong for the services in the docker compose file as it wants a list from u so ur file should look like this:
services:
service1:
networks:
- projectserv-net
services:
service1:
networks:
- projectserv-net
blueberriesiftheywerecats
same error
cap5lut
cap5lut12mo ago
did u check the postgres logs to see if its actually up and running?
blueberriesiftheywerecats
2023-12-02 11:39:54 Error: Database is uninitialized and superuser password is not specified. 2023-12-02 11:39:54 You must specify POSTGRES_PASSWORD to a non-empty value for the 2023-12-02 11:39:54 superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run". 2023-12-02 11:39:54 2023-12-02 11:39:54 You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all 2023-12-02 11:39:54 connections without a password. This is not recommended. 2023-12-02 11:39:54 2023-12-02 11:39:54 See PostgreSQL documentation about "trust": 2023-12-02 11:39:54 https://www.postgresql.org/docs/current/auth-trust.html
PostgreSQL Documentation
21.4. Trust Authentication
21.4. Trust Authentication # When trust authentication is specified, PostgreSQL assumes that anyone who can connect to the server is authorized …
cap5lut
cap5lut12mo ago
hmm so its indeed not running, but i dunno why its complaining maybe its not liking root as password, can u try something else?
blueberriesiftheywerecats
same
cap5lut
cap5lut12mo ago
this shouldnt make a difference, but can u try this notation instead?
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=root
- POSTGRES_DB=projectservdb
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=root
- POSTGRES_DB=projectservdb
blueberriesiftheywerecats
same as always btw im starting compose with docker-compose up wait okay it just started properly idk why
cap5lut
cap5lut12mo ago
weird indeed
blueberriesiftheywerecats
but there is still c# error
cap5lut
cap5lut12mo ago
if u run docker ps is it showing the postgres container?
blueberriesiftheywerecats
it worked because of
docker-compose run app
docker-compose run app
instead of
docker-compose up
docker-compose up
cap5lut
cap5lut12mo ago
and what does docker logs postgres show?
cap5lut
cap5lut12mo ago
can u show ur current docker compose file?
blueberriesiftheywerecats
networks:
projectserv-net:
driver: bridge

services:
app:
container_name: projectserv
build:
context: .
dockerfile: Dockerfile
ports:
- "80:80"
depends_on:
- postgres
networks:
- projectserv-net
postgres:
container_name: postgres
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=root
- POSTGRES_DB=projectservdb
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
- projectserv-net
volumes:
postgres-data:

networks:
projectserv-net:
driver: bridge

services:
app:
container_name: projectserv
build:
context: .
dockerfile: Dockerfile
ports:
- "80:80"
depends_on:
- postgres
networks:
- projectserv-net
postgres:
container_name: postgres
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=root
- POSTGRES_DB=projectservdb
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
- projectserv-net
volumes:
postgres-data:

cap5lut
cap5lut12mo ago
output of docker network inspect projectserv-net?
cap5lut
cap5lut12mo ago
hmm maybe it doesnt like the - in the name try to change that and restart both containers
blueberriesiftheywerecats
same
cap5lut
cap5lut12mo ago
docker network ls?
cap5lut
cap5lut12mo ago
docker network inspect projectserv_projectservnet?
blueberriesiftheywerecats
PS C:\Users\taras\Desktop\ProjectServ> docker network inspect projectserv_projectservnet
[
{
"Name": "projectserv_projectservnet",
"Id": "18fd9f5e774e63e4693a660f09aba22a1f15a57938f3e81923e6a948170cf454",
"Created": "2023-12-02T10:12:05.315903142Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.22.0.0/16",
"Gateway": "172.22.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"574593d6590881fc535878abf93feef3f8c1d5e567cf924767d3ef6083a5b0c0": {
"Name": "postgres",
"EndpointID": "450b385f1c2cc37e7e233d893c2f2f5d004ea4778fe07c0d568329b62d7be4dd",
"MacAddress": "02:42:ac:16:00:02",
"IPv4Address": "172.22.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "projectservnet",
"com.docker.compose.project": "projectserv",
"com.docker.compose.version": "2.23.0"
}
}
]
PS C:\Users\taras\Desktop\ProjectServ> docker network inspect projectserv_projectservnet
[
{
"Name": "projectserv_projectservnet",
"Id": "18fd9f5e774e63e4693a660f09aba22a1f15a57938f3e81923e6a948170cf454",
"Created": "2023-12-02T10:12:05.315903142Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.22.0.0/16",
"Gateway": "172.22.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"574593d6590881fc535878abf93feef3f8c1d5e567cf924767d3ef6083a5b0c0": {
"Name": "postgres",
"EndpointID": "450b385f1c2cc37e7e233d893c2f2f5d004ea4778fe07c0d568329b62d7be4dd",
"MacAddress": "02:42:ac:16:00:02",
"IPv4Address": "172.22.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "projectservnet",
"com.docker.compose.project": "projectserv",
"com.docker.compose.version": "2.23.0"
}
}
]
cap5lut
cap5lut12mo ago
can u show me the updated compose file again?
blueberriesiftheywerecats
networks:
projectservnet:
driver: bridge

services:
app:
container_name: projectserv
build:
context: .
dockerfile: Dockerfile
ports:
- "80:80"
depends_on:
- postgres
networks:
- projectservnet
postgres:
container_name: postgres
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=root
- POSTGRES_DB=projectservdb
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
- projectservnet
volumes:
postgres-data:

networks:
projectservnet:
driver: bridge

services:
app:
container_name: projectserv
build:
context: .
dockerfile: Dockerfile
ports:
- "80:80"
depends_on:
- postgres
networks:
- projectservnet
postgres:
container_name: postgres
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=root
- POSTGRES_DB=projectservdb
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
- projectservnet
volumes:
postgres-data:

cap5lut
cap5lut12mo ago
and u still get the Name or service not known exception if u try to run the app container? 😒
cap5lut
cap5lut12mo ago
and the postgres container is waiting for connections right?
cap5lut
cap5lut12mo ago
hmmm thats weird tbh im out of ideas, the docker compose file looks correct to me, same for the connection string can u try docker-compose down followed by docker-compose up -d and then docker ps? i want to see the output from all of them
blueberriesiftheywerecats
no containers because of docker-compose up -d maybe there are other ways to automatically update db? I think i fixed it
blueberriesiftheywerecats
but how can i access that app ?
No description
blueberriesiftheywerecats
it does not look like my app
No description
No description
blueberriesiftheywerecats
ok, now it fully woking but idk why there is items in my db nvm btw i fixed whole thing by removing

RUN dotnet tool install --global dotnet-ef --version 7.0.13
ENV PATH="${PATH}:/root/.dotnet/tools"
RUN dotnet ef database update


RUN dotnet tool install --global dotnet-ef --version 7.0.13
ENV PATH="${PATH}:/root/.dotnet/tools"
RUN dotnet ef database update

and adding to the context Database.EnsureCretead() $close
MODiX
MODiX12mo ago
Use the /close command to mark a forum thread as answered
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
so, how can I run .sh after I deployed db and app? because as I know Database.EnsureCretead is not a good option to update db
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
as i know it makes db from context class
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
not from migrations
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
as i know it makes db from context class not from migrations, which means I cant make a rollback
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
Tim Brown
Code Buckets
Applying Entity Framework Migrations to a Docker Container
I’m going to run through how to deploy an API and a database into two separate Docker containers then apply Entity Framework migrations. This will create and populate the database with the co…
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
cap5lut
cap5lut12mo ago
good catch and thanks for the cc 🙂
Want results from more Discord servers?
Add your server