C
C#2y ago
Hulkstance

Dockerfile cannot find dependent project in the parent directory

.
+---src
| +---MarketData.Api
| +---MarketData.Messages
| +---MarketData.Subscriber
| +---Dockerfile
+---MarketData.sln
.
+---src
| +---MarketData.Api
| +---MarketData.Messages
| +---MarketData.Subscriber
| +---Dockerfile
+---MarketData.sln
# Stage 1 - Build
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder

WORKDIR /app/src

# Restore
COPY ./src/MarketData.Messages/MarketData.Messages.csproj ./MarketData.Messages/
COPY *.csproj .
RUN dotnet restore

# Build
COPY . .
RUN dotnet publish -c Release -o /app/publish --no-self-contained --no-restore

# Stage 2 - Publish
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app

RUN addgroup --system --gid 101 app \
&& adduser --system --ingroup app --uid 101 app


COPY --from=builder --chown=app:app /app/publish .

USER app
ENTRYPOINT ["./MarketData.Subscriber"]
# Stage 1 - Build
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder

WORKDIR /app/src

# Restore
COPY ./src/MarketData.Messages/MarketData.Messages.csproj ./MarketData.Messages/
COPY *.csproj .
RUN dotnet restore

# Build
COPY . .
RUN dotnet publish -c Release -o /app/publish --no-self-contained --no-restore

# Stage 2 - Publish
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app

RUN addgroup --system --gid 101 app \
&& adduser --system --ingroup app --uid 101 app


COPY --from=builder --chown=app:app /app/publish .

USER app
ENTRYPOINT ["./MarketData.Subscriber"]
The issue is within that statement: COPY ./src/MarketData.Messages/MarketData.Messages.csproj ./MarketData.Messages/.
failed to compute cache key: "/src/MarketData.Messages/MarketData.Messages.csproj" not found: not found
15 Replies
Cisien
Cisien2y ago
How are you running the build? It ahould be from the root and docker build . -f src/Dockerfile The ‘.’ Denotes the build context, or in other words, the parent directory that is made available to the docker build process
Hulkstance
Hulkstance2y ago
I wish I wrote that post earlier. It took me 2 hours thanks a lot! 🙂 @Cisien, I need to create Dockerfiles for MarketData.Subscriber and MarketData.Api which now works thanks to you. However, what about the .dockerignore file? Do I keep it into the root directory or next to the Dockerfiles in both projects?
Cisien
Cisien2y ago
Either, like .gitignore it applies scoped to the directory its in. Usually one at the root is sufficient
Hulkstance
Hulkstance2y ago
Thank you very much! 🙂 @Cisien damn, there is an issue with the .proto files
Hulkstance
Hulkstance2y ago
Hulkstance
Hulkstance2y ago
# Stage 1 - Build
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder

WORKDIR /app/src

# Restore
COPY ["src/MarketData.Messages/MarketData.Messages.csproj", "MarketData.Messages/"]
COPY ["src/MarketData.Subscriber/MarketData.Subscriber.csproj", "MarketData.Subscriber/"]
RUN dotnet restore "MarketData.Subscriber/MarketData.Subscriber.csproj"

# Build
COPY . .
RUN dotnet publish "MarketData.Subscriber/MarketData.Subscriber.csproj" -c Release -o /app/publish --no-self-contained --no-restore

# Stage 2 - Publish
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app

RUN addgroup --system --gid 101 app \
&& adduser --system --ingroup app --uid 101 app

COPY --from=builder --chown=app:app /app/publish .

USER app
ENTRYPOINT ["./MarketData.Subscriber"]
# Stage 1 - Build
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder

WORKDIR /app/src

# Restore
COPY ["src/MarketData.Messages/MarketData.Messages.csproj", "MarketData.Messages/"]
COPY ["src/MarketData.Subscriber/MarketData.Subscriber.csproj", "MarketData.Subscriber/"]
RUN dotnet restore "MarketData.Subscriber/MarketData.Subscriber.csproj"

# Build
COPY . .
RUN dotnet publish "MarketData.Subscriber/MarketData.Subscriber.csproj" -c Release -o /app/publish --no-self-contained --no-restore

# Stage 2 - Publish
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app

RUN addgroup --system --gid 101 app \
&& adduser --system --ingroup app --uid 101 app

COPY --from=builder --chown=app:app /app/publish .

USER app
ENTRYPOINT ["./MarketData.Subscriber"]
Cisien
Cisien2y ago
Looks like your not copying everything in
Hulkstance
Hulkstance2y ago
Hulkstance
Hulkstance2y ago
that should be it @Cisien, normally I would have to build first the Messages project, so it can generate the .cs files out of the .proto files maybe that's causing it but I'm not sure how to do it with Dockerfile
Cisien
Cisien2y ago
Might be Be explicit with your steps Try creating a project reference to the messages project from the one that fails That should get the ordering sorted
Hulkstance
Hulkstance2y ago
MarketData.Subscriber already references the MarketData.Messages
Hulkstance
Hulkstance2y ago
Hulkstance
Hulkstance2y ago
Hulkstance
Hulkstance2y ago
and this is the Messages.csproj it builds just fine locally @Cisien is there a way to inspect what's in /app/src on the docker? like which folders, which files
Cisien
Cisien2y ago
You can run shell commands