Build Step "Docker build" is picking wrong context
Hi,
when running a simple docker build on the agent, I always run into path related problems (TeamCity Professional 2019.2.2 (build 71923)). The docker file is as following:
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-sac2016 AS build
WORKDIR /app
COPY ["dockertest.csproj", "./"]
RUN dotnet restore "dockertest.csproj"
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1803
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "dockertest.dll"]
When running "docker build" on my local machine from the folder the docker file is contained, it's all working fine.
When running this script in a build step (file content), it always picks the wrong context directory:
COPY failed: CreateFile \\?\C:\ProgramData\Docker\tmp\docker-builder698629353\dockertest.csproj: The system cannot find the file specified.
I don't know why the path contains the strange "\\?\" in the beginning. The build agent for TeamCity is on "D" Drive (not C - I assume this doesn't matter as docker is building; but D also contains the source in the Agent).
What should I fix/change to solve this problem with the path in TeamCity?
Any help would be great.
Please sign in to leave a comment.
In regards to "\\?\" prefix, I would suggest to check this MSDN article regarding long paths on Windows systems:
https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN
Speaking of the context issue - could you please confirm where the dockerfile is located? If you could share your build step settings, that would be very helpful.
What user is agent running as? Have you tried to manually build image under the same identity? Chances are that the user you tested with has context folder in its environment, while agent identity has not.
May I also ask you to provide an extract from your build log regarding the docker build part?
The Dockerfile is contained within the Agents work folder. In this case it's 'D:\TeamCity_Agents\Agent2\BuildAgent\work\7cc0e3eea7b3d66d\dockertest'.
The Agent runs as admin and should have access to the folder mentioned in the output (It's on windows server 2016).
The docker build step is currently the only one in the configuration (except checkout of the source from vcs - I can see that the project is on the agents working directory).
On the dockerfile contents themselves, I`ve did a quick test where dockerfile (minimal setup, composed of lines below) was being checked out and built:
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-sac2016 AS build
WORKDIR /app
COPY [".gitignore", "./"]
The COPY instruction worked as expected, both on manual execution and via TeamCity instance (note that I have used the same user identity for both operations).
Log hints that a temporary dockerfile is being created during the build as per this line:
[12:20:22][Step 5/5] Temporary file was created: D:\TeamCity_Agents\Agent2\BuildAgent\work\7cc0e3eea7b3d66d\Dockerfile_TC_1586341222129-temp
[12:20:22][Step 5/5] Starting: docker build -t 0.0.1.22 --pull -f D:\TeamCity_Agents\Agent2\BuildAgent\work\7cc0e3eea7b3d66d\Dockerfile_TC_1586341222129-temp
Please note that this temporary file is also being fed to docker build command; as you have stated you have dockertest file in checkout folder, I`d expect something like:
docker build -t 0.0.1.22 --pull -f D:\TeamCity_Agents\Agent2\BuildAgent\work\7cc0e3eea7b3d66d\dockertest
Could you please share a screenshot of "Build Step" settings screen ("Docker Command Parameters" section is specifically interesting here). As a double-check, may I also ask you to confirm that, if at "Dockerfile source" dropdown you would pick "URL"/"File content" options, respective fields would be empty for you?
From my understanding, it somehow picks the wrong source folder for copy. As the checkout directory it: D:\TeamCity_Agents\Agent2\BuildAgent\work\7cc0e3eea7b3d66d
But it tries to copy from:
\\?\C:\ProgramData\Docker\tmp\docker-builder081045300\dockertest.csproj
Ok, I fixed it. The work folder still contains one other folder. My bad. Thanks for your help.
Hi, I'm having this exact issue but couldn't understand the resolution. I'm providing the dockerfile from the build step, and seeing this:
COPY failed: CreateFile \\?\C:\ProgramData\docker\tmp\docker-builder033924972\gui: The system cannot find the path specified.
And I can see that the log file is using the correct workspace:
[22:38:42][Step 4/6] Temporary file was created: C:\BuildAgent\work\b2ebd193d65497ae\Dockerfile_TC_1595468322060-temp
[22:38:42][Step 4/6] Starting: docker build -t gui:tc1.0.0 --pull -f C:\BuildAgent\work\b2ebd193d65497ae\Dockerfile_TC_1595468322060-temp .
[22:38:42][Step 4/6] in directory: C:\BuildAgent\work\b2ebd193d65497ae
I'm running this on the dockerfile:
WORKDIR /app
COPY gui/ /app/