✅ Docker issue

i have this folder structure
46 Replies
blueberriesiftheywerecats
docker/
Dockerfiles/
Client.Dockerfile
Server.Dockerfile
docker-compose.yml

server/
Essential/
Essential.Web
Essential.Common
...
Essential.sln
docker/
Dockerfiles/
Client.Dockerfile
Server.Dockerfile
docker-compose.yml

server/
Essential/
Essential.Web
Essential.Common
...
Essential.sln
Server.Dockerfile
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base

USER app
WORKDIR /app
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Essential/Essential.Infrastructure/Essential.Infrastructure.csproj", "server/Essential/Essential.Infrastructure/"]
COPY ["Essential/Essential.Web/Essential.Web.csproj", "server/Essential/Essential.Web/"]
COPY ["Essential/Essential.Domain/Essential.Domain.csproj", "server/Essential/Essential.Domain/"]
COPY ["Essential/Essential.Common/Essential.Common.csproj", "server/Essential/Essential.Common/"]
RUN dotnet restore "./server/Essential/Essential.Web/Essential.Web.csproj"

WORKDIR "/src/server/Essential/Essential.Web"
COPY . .

RUN dotnet build "./Essential.Web.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Essential.Web.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Essential.Web.dll"]
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base

USER app
WORKDIR /app
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Essential/Essential.Infrastructure/Essential.Infrastructure.csproj", "server/Essential/Essential.Infrastructure/"]
COPY ["Essential/Essential.Web/Essential.Web.csproj", "server/Essential/Essential.Web/"]
COPY ["Essential/Essential.Domain/Essential.Domain.csproj", "server/Essential/Essential.Domain/"]
COPY ["Essential/Essential.Common/Essential.Common.csproj", "server/Essential/Essential.Common/"]
RUN dotnet restore "./server/Essential/Essential.Web/Essential.Web.csproj"

WORKDIR "/src/server/Essential/Essential.Web"
COPY . .

RUN dotnet build "./Essential.Web.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Essential.Web.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Essential.Web.dll"]
docker-compose.yml
services:
server:
image: server
container_name: server
ports:
- "5072:8080"
environment:
- ASPNETCORE_ENVIRONMENT=Development
build:
context: ../server
dockerfile: ../docker/Dockerfiles/Server.Dockerfile
networks:
- mynetwork

postgres:
image: postgres
container_name: postgres
restart: always
environment:
POSTGRES_PASSWORD: root
POSTGRES_USER: postgres
POSTGRES_DB: essentialdb
ports:
- 5432:5432
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- mynetwork

client:
image: client
container_name: client
build:
context: ../client
dockerfile: ../docker/Dockerfiles/Client.Dockerfile
hostname: client
ports:
- "3000:3000"
env_file:
- .env

volumes:
pgdata:

networks:
mynetwork:
driver: bridge
services:
server:
image: server
container_name: server
ports:
- "5072:8080"
environment:
- ASPNETCORE_ENVIRONMENT=Development
build:
context: ../server
dockerfile: ../docker/Dockerfiles/Server.Dockerfile
networks:
- mynetwork

postgres:
image: postgres
container_name: postgres
restart: always
environment:
POSTGRES_PASSWORD: root
POSTGRES_USER: postgres
POSTGRES_DB: essentialdb
ports:
- 5432:5432
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- mynetwork

client:
image: client
container_name: client
build:
context: ../client
dockerfile: ../docker/Dockerfiles/Client.Dockerfile
hostname: client
ports:
- "3000:3000"
env_file:
- .env

volumes:
pgdata:

networks:
mynetwork:
driver: bridge
blueberriesiftheywerecats
and when i try to
docker-compose up
docker-compose up
i get this error
No description
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
my friend and chat gpt already fixed it, but neither me nor my friend didnt understand how so this is link to the commit that contains the problem https://github.com/zhurak-v/essential-shop/tree/4c923c8ae44ea91ce9500919b528a22c6c1e0eb3 and this is fixed Dockerfile
# Use the ASP.NET runtime image as the base image for the final stage
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080

# Use the SDK image for the build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src

# Copy the csproj files and restore dependencies
COPY ["Essential/Essential.Web/Essential.Web.csproj", "Essential/Essential.Web/"]
COPY ["Essential/Essential.Infrastructure/Essential.Infrastructure.csproj", "Essential/Essential.Infrastructure/"]
COPY ["Essential/Essential.Domain/Essential.Domain.csproj", "Essential/Essential.Domain/"]
COPY ["Essential/Essential.Common/Essential.Common.csproj", "Essential/Essential.Common/"]
RUN dotnet restore "Essential/Essential.Web/Essential.Web.csproj"

# Copy the remaining source code and build the application
COPY . .
WORKDIR "/src/Essential/Essential.Web"
RUN dotnet build "Essential.Web.csproj" -c $BUILD_CONFIGURATION -o /app/build

# Publish the application
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "Essential.Web.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# Use the base image for the final stage
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Essential.Web.dll"]
# Use the ASP.NET runtime image as the base image for the final stage
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080

# Use the SDK image for the build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src

# Copy the csproj files and restore dependencies
COPY ["Essential/Essential.Web/Essential.Web.csproj", "Essential/Essential.Web/"]
COPY ["Essential/Essential.Infrastructure/Essential.Infrastructure.csproj", "Essential/Essential.Infrastructure/"]
COPY ["Essential/Essential.Domain/Essential.Domain.csproj", "Essential/Essential.Domain/"]
COPY ["Essential/Essential.Common/Essential.Common.csproj", "Essential/Essential.Common/"]
RUN dotnet restore "Essential/Essential.Web/Essential.Web.csproj"

# Copy the remaining source code and build the application
COPY . .
WORKDIR "/src/Essential/Essential.Web"
RUN dotnet build "Essential.Web.csproj" -c $BUILD_CONFIGURATION -o /app/build

# Publish the application
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "Essential.Web.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# Use the base image for the final stage
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Essential.Web.dll"]
idk, it looks same but without server folder in projects when copying, can u help me understand what changed? and the link prolly to private repo, but it does not matter because problem in dockerfile
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
i showed folder structure so it doesnt matter i think, it was just dockerfile
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
alr im on it
blueberriesiftheywerecats
GitHub
GitHub - TarasKo444/temp
Contribute to TarasKo444/temp development by creating an account on GitHub.
blueberriesiftheywerecats
there is nothing really to be private, its just project that me and my friend have started it breaks when you add server/ folder when copying in dockefile but i dont understand why
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
yea i have the same when i swap COPY and WORKDIR lines
blueberriesiftheywerecats
Stack Overflow
Getting "Program does not contain a static 'Main' method suitable f...
I'm running into an issue using Docker and couldn't find a proper solution. I'm trying to build a Docker image using .NET SDK 2.1. The thing is that when Docker tries to run the build statement, it...
blueberriesiftheywerecats
but it lead to this error
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
btw its weird stuff going on here, you can see folders like this /src/server/Essential/Essential.Web/Essential/Essential.Domain/ /src/server/Essential/Essential.Web/Essential/Essential.Infrastructure/ /src/server/Essential/Essential.Web/Essential/Essential.Web which is obviously wrong
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
but changing the order doesnt help
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
yeah it was generated so i just left it alr thanks for advice
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
i was trying to do
RUN ls
RUN ls
but it just printed nothing
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
ahh that helpful
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
so overall was it dockers bug or i just messed up with path
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
because im trying to understand whats going on in that dockerfile and why do we have that csproj out nowhere
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
yea makes sense
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
:skillissue:
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
what could be wierd?
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
yea I get it, thats why i added COPY for all Class Library projects
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX3w ago
ARG DOTNET_VERSION=8.0
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build
WORKDIR /sln

COPY ./*.sln ./nuget.config ./

# Copy the main source project files
COPY src/*/*.csproj ./
RUN for file in $(ls *.csproj); do mkdir -p src/${file%.*}/ && mv $file src/${file%.*}/; done

# Copy the test project files
COPY test/*/*.csproj ./
RUN for file in $(ls *.csproj); do mkdir -p test/${file%.*}/ && mv $file test/${file%.*}/; done

RUN dotnet restore

# possible FROM .... for multi stage here
COPY . .
RUN dotnet build

RUN dotnet publish --project src/Your.Project/Your.Project.csproj -c Release -o /publish --no-restore

# final stage/image
ARG DOTNET_VERSION=8.0
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}
WORKDIR /app
COPY --from=build /publish .
ENTRYPOINT ["dotnet", "Your.Project.dll"]
ARG DOTNET_VERSION=8.0
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build
WORKDIR /sln

COPY ./*.sln ./nuget.config ./

# Copy the main source project files
COPY src/*/*.csproj ./
RUN for file in $(ls *.csproj); do mkdir -p src/${file%.*}/ && mv $file src/${file%.*}/; done

# Copy the test project files
COPY test/*/*.csproj ./
RUN for file in $(ls *.csproj); do mkdir -p test/${file%.*}/ && mv $file test/${file%.*}/; done

RUN dotnet restore

# possible FROM .... for multi stage here
COPY . .
RUN dotnet build

RUN dotnet publish --project src/Your.Project/Your.Project.csproj -c Release -o /publish --no-restore

# final stage/image
ARG DOTNET_VERSION=8.0
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}
WORKDIR /app
COPY --from=build /publish .
ENTRYPOINT ["dotnet", "Your.Project.dll"]
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
yea this one works well too
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
blueberriesiftheywerecats
well, thanks, now I better understand docker 🥰
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX3w ago
If you have no further questions, please use /close to mark the forum thread as answered
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View