'Workdir and dot at the end of directory path

I'm looking at this tutorial: https://docs.microsoft.com/en-us/learn/modules/implement-docker-multi-stage-builds/3-examine-multi-stage-dockerfiles

And this part confuses me:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["WebApplication1.csproj", ""]
RUN dotnet restore "./WebApplication1.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build

Why would you use WORKDIR twice here? Aren't we already in the src?
Does the dot at the end (/src/.) has any additional meaning?



Solution 1:[1]

Adding twice WORKDIR is for clarity. As best practise adding WORKDIR with absolute path is recommended for readability and maintenance purpose.

Working directory can also be verify as below

docker run -it imageName pwd

replace imageName -with actual Image Name

pwd with cd (windows current directory command)

Link for Docker best practises, refer WORKDIR section.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1