C
C#10mo ago
Ares

[ASP.NET] Docker build not working properly.

so basically i made and pushed a docker image to the hub repositoory. And everytime i push to github, there is a github action that also updates the docker image and then on render.com is updated too. so my docker image works fine for deploying to a cloud provider. but the problem is that if i want other people to pull my docker image from online and run it locally, they are unable to do that. when i pull and then run docker compose up, I get the following error:
26 Replies
Ares
AresOP10mo ago
[+] Building 1.1s (12/14) docker:default
=> CACHED [server build 2/4] COPY . /source 0.0s
=> CACHED [server build 3/4] WORKDIR /source/realTimePollsApp 0.0s
=> ERROR [server build 4/4] RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages dotnet publish -a $ 0.5s
------
> [server build 4/4] RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages dotnet publish -a ${TARGETARCH/amd64/x64} --use-current-runtime --self-contained false -o /app:
0.436 MSBuild version 17.9.4+90725d08d for .NET
0.436 MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
------
failed to solve: process "/bin/sh -c dotnet publish -a ${TARGETARCH/amd64/x64} --use-current-runtime --self-contained false -o /app" did not complete successfully: exit code: 1
[+] Building 1.1s (12/14) docker:default
=> CACHED [server build 2/4] COPY . /source 0.0s
=> CACHED [server build 3/4] WORKDIR /source/realTimePollsApp 0.0s
=> ERROR [server build 4/4] RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages dotnet publish -a $ 0.5s
------
> [server build 4/4] RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages dotnet publish -a ${TARGETARCH/amd64/x64} --use-current-runtime --self-contained false -o /app:
0.436 MSBuild version 17.9.4+90725d08d for .NET
0.436 MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
------
failed to solve: process "/bin/sh -c dotnet publish -a ${TARGETARCH/amd64/x64} --use-current-runtime --self-contained false -o /app" did not complete successfully: exit code: 1
this doesnt make sense to me cause the .sln file is in the same directory as the compose.yaml and the Dockerfile, so why is it saying th eabove? could anyone help me with this?
Keswiik
Keswiik10mo ago
what does your compose file look like? Because the output above looks like you are attempting to build a container, not pull and run an existing one.
Ares
AresOP10mo ago
my compose.yaml looks like this:
services:
server:
build:
context: .
target: final
ports:
- 8080:8080
environment:
- ASPNETCORE_ENVIRONMENT=Development
- IS_DOCKER=true
depends_on:
db:
condition: service_healthy
develop:
watch:
- action: rebuild
path: .
db:
image: postgres
restart: always
user: postgres
secrets:
- db-password
volumes:
- db-data:/var/lib/postgresql/data
- ./init-db.sql:/docker-entrypoint-initdb.d/init-db.sql
environment:
- POSTGRES_DB=realtime_poll
env_file:
- ./postgres.env

expose:
- 5432
healthcheck:
test: [ "CMD", "pg_isready" ]
interval: 10s
timeout: 5s
retries: 5
volumes:
db-data:
secrets:
db-password:
file: db/password.txt
services:
server:
build:
context: .
target: final
ports:
- 8080:8080
environment:
- ASPNETCORE_ENVIRONMENT=Development
- IS_DOCKER=true
depends_on:
db:
condition: service_healthy
develop:
watch:
- action: rebuild
path: .
db:
image: postgres
restart: always
user: postgres
secrets:
- db-password
volumes:
- db-data:/var/lib/postgresql/data
- ./init-db.sql:/docker-entrypoint-initdb.d/init-db.sql
environment:
- POSTGRES_DB=realtime_poll
env_file:
- ./postgres.env

expose:
- 5432
healthcheck:
test: [ "CMD", "pg_isready" ]
interval: 10s
timeout: 5s
retries: 5
volumes:
db-data:
secrets:
db-password:
file: db/password.txt
i dont want to spam this chat, so here is my Dockerfile
Keswiik
Keswiik10mo ago
That compose file is never going to run the image that github deploys, it will only build a new one locally.
Ares
AresOP10mo ago
i know, i have to do docker pull image_name:latest to get the image, and then it shows up in Docker Hub. and then after that I do docker compose up --build to get the postgres image to show up as the database. and then im supposed to do docker run right? am i misunderstanding this?
Keswiik
Keswiik10mo ago
there is no reason to do docker-compose up --build when creating running a container pulled from a registry and also no reason to use docker run either docker-compose up will 1) build any images that specify dockerifles / build contexts 2) pull any images not found in your local cache 3) start the containers As for this error, I don't have any suggestions outside of adding in additional steps to write the contents of the current directory to console. If you want to test the image that is getting deployed to github, I'd honestly just create a new compose file and put it somewhere else
Ares
AresOP10mo ago
i dont really understand to be honest, is tarted learnign docker a few days ago. but when i do docker pull then i have to do docker run next right? but when I do i see this in the console:
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
Storing keys in a directory '/home/app/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed. For more information go to https://aka.ms/aspnet/dataprotectionwarning
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[62]
User profile is available. Using '/home/app/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58]
Creating key {e6be7809-e17d-47e7-8428-64c382493711} with creation date 2024-02-28 04:28:34Z, activation date 2024-02-28 04:28:34Z, and expiration date 2024-05-28 04:28:34Z.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {e6be7809-e17d-47e7-8428-64c382493711} may be persisted to storage in unencrypted form.
info: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[39]
Writing data to file '/home/app/.aspnet/DataProtection-Keys/key-e6be7809-e17d-47e7-8428-64c382493711.xml'.
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://[::]:8080
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
Storing keys in a directory '/home/app/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed. For more information go to https://aka.ms/aspnet/dataprotectionwarning
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[62]
User profile is available. Using '/home/app/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58]
Creating key {e6be7809-e17d-47e7-8428-64c382493711} with creation date 2024-02-28 04:28:34Z, activation date 2024-02-28 04:28:34Z, and expiration date 2024-05-28 04:28:34Z.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {e6be7809-e17d-47e7-8428-64c382493711} may be persisted to storage in unencrypted form.
info: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[39]
Writing data to file '/home/app/.aspnet/DataProtection-Keys/key-e6be7809-e17d-47e7-8428-64c382493711.xml'.
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://[::]:8080
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app
and then when i go to localhost:8080 in the browser, i get the above error.
No description
Ares
AresOP10mo ago
and then when i look in my docker hub, i dont see my postgres image
No description
Keswiik
Keswiik10mo ago
are you actually using docker pull and docker run, or are you using docker-compose?
Ares
AresOP10mo ago
no i am doing docker pull jbrown58/realtime-poll and then docker run jbrown58/realtime-poll
Keswiik
Keswiik10mo ago
that is your problem, docker and docker-compose behave very differently docker run requires you to manually pass in all of the configuration options needed to make a container work properly (exposing ports, mounting paths, etc) docker-compose reads from a docker-compose.yml file that lets you configure the container So when you do docker run jbrown58/realtime-poll, it has no idea that a database is required for things to work. It also doesn't know that it should be exposing your app on port 8080
Ares
AresOP10mo ago
ok so i should always use docker-compose since i am using a compose.yaml?
Keswiik
Keswiik10mo ago
yup
Ares
AresOP10mo ago
ok one sec
Ares
AresOP10mo ago
ok i did docker compose pull, and i see my postgres database now, but it didnt also bring the app with it
No description
Ares
AresOP10mo ago
it is kind of the opposite of before when it would bring the app but not the database
Keswiik
Keswiik10mo ago
docker-compose pull does not start containers, it only downloads the most recent version of the image (if the local one is outdated)
Ares
AresOP10mo ago
but this image is just the database, is my app not part of the multi container? ^ ok that probbaly doesnt make any sense i think cause, you pull images not container
Keswiik
Keswiik10mo ago
What is the exact command you used?
Ares
AresOP10mo ago
i did docker-compose run jbrown58/realtime-poll but it said no such service: jbrown58/realtime-poll and didnt do anything, so i googled and it said that you haev to do docker-compose pull and then do the previous command but that didn twork either
Keswiik
Keswiik10mo ago
ok, it seems you are misunderstanding how docker-compose works in general
Ares
AresOP10mo ago
yes i think so, i remember when i was using docker-compose at first but i stopped using it for some reason
Keswiik
Keswiik10mo ago
Docker Documentation
How Compose works
Understand how Compose works and the Compose application model with an illustrative example
From An unknown user
From An unknown user
Keswiik
Keswiik10mo ago
If you haven't read the docs on how compose works, I'd suggest you take a look at them But I'll give a quick TL;DR on some of the more common commands up - starts containers that you have defined in your compose file. Can start all or specify specific services to run. If you want to start your app only, you'd do docker-compose up -d server because, in your compose file, the app's service is named server down - stops containers build - builds all services that specify a build section in their config pull - pulls the latest versions for all services that use an image
Keswiik
Keswiik10mo ago
Docs for the compose CLI can be found here: https://docs.docker.com/compose/reference/
Docker Documentation
Overview of docker compose CLI
Overview of the Docker Compose CLI
From An unknown user
From An unknown user
Ares
AresOP10mo ago
ok thank you
Want results from more Discord servers?
Add your server