Docker Community Forums

Share and learn in the Docker community.

Dockerfile - how to replace file inside container when run docker build command

Hello. I am new to Docker.
I have a standard Dockerfile that VS made for a .net Core MVC project.
Here it is:

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR / app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR / src
COPY ["EG_TESTIMAGE / EG_TESTIMAGE.csproj", "EG_TESTIMAGE /"]
RUN dotnet restore "EG_TESTIMAGE / EG_TESTIMAGE.csproj"
COPY. ...
WORKDIR "/ src / EG_TESTIMAGE"

RUN dotnet build "EG_TESTIMAGE.csproj" -c Release -o / app / build

FROM build AS publish
RUN dotnet publish "EG_TESTIMAGE.csproj" -c Release -o / app / publish


FROM base AS final
WORKDIR / app
COPY --from = publish / app / publish.

ENTRYPOINT ["dotnet", "EG_TESTIMAGE.dll"]

I am using nlog. There are two configuration files nlog.config and nlog.config.development.
When running docker build command, I need to copy nlog.config to nlog.config.development. (For correct operation of logs on the server with ASPNETCORE_ENVIRONMENT = development)

I am trying to make the command:

COPY nlog.config nlog.config.development - fails.

How to do it correctly?

This is the strangest Dockerfile I have ever seen, but how does your copy fail? Is there an error message or you just cannot find the file inside the container?

This is standard file by Visual Studio. Here is the link Visual Studio Container Tools build and debug overview - Visual Studio (Windows) | Microsoft Docs what describe this file.

Thank you for the link. The code you inserted is different. The version in the documentation has a correct syntax. Although I cannot help without an error message. The problem could be how you refer to the file on the host with an incorrect path or can be anything else.