I’m facing an issue I’m not getting why and how to solve it.
Can you help, or give me some hints to figure out what’s wrong with my Dockerfile
?
code so far:
# Official .NET SDK image to build and run the .NET application
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
# Setting the working directory
WORKDIR /app
# Set up proxy environment variables for the build
ENV https_proxy=http://zscaler-prod.fs01.vwf.vwfs-ad:8080
ENV http_proxy=http://zscaler-prod.fs01.vwf.vwfs-ad:8080
# Copy csproj and restore any dependencies (via NuGet)
COPY *.csproj ./
RUN dotnet restore
# Copy the project files into the container
COPY . ./
RUN dotnet build
# Install the Playwright CLI tool globally
RUN dotnet tool install --global Microsoft.Playwright.CLI
# Update the PATH environment variable to include the dotnet tool path
ENV PATH="${PATH}:/root/.dotnet/tools"
# Navigate to the output directory where the build artifacts are located
WORKDIR /app/bin/Release/net6.0
# Playwright CLI tool to install the necessary browsers
RUN playwright install
# Run .NET tests using Playwright
RUN dotnet test --settings test.runsettings --filter "TestCategory=loginRIA"
Error log:
#0 building with "default" instance using docker driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 1.19kB done
#1 DONE 0.0s
#2 [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0
#2 DONE 0.1s
#3 [internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s
#4 [ 1/10] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:e5a27c7f2a5f679f994106aa330585a7108e2812a8367e7686c13451e7fd27a0
#4 DONE 0.0s
#5 [internal] load build context
#5 transferring context: 125.58kB 0.2s done
#5 DONE 0.2s
#6 [ 2/10] WORKDIR /app
#6 CACHED
#7 [ 3/10] COPY *.csproj ./
#7 CACHED
#8 [ 4/10] RUN dotnet restore
#8 CACHED
#9 [ 5/10] COPY . ./
#9 DONE 0.7s
#10 [ 6/10] RUN dotnet build
#10 0.661 MSBuild version 17.3.2+561848881 for .NET
#10 1.330 Determining projects to restore...
#10 2.166 Restored /app/MilesBelgiumRIA.csproj (in 454 ms).
#10 2.308 SpecFlowFeatureFiles: Features/BE-Accounting.feature;Features/BE-Contract.feature;Features/BE-RelationManagement.feature;Features/BE-Sales.feature;Features/BE-Smoke.feature
#10 2.379 -> Using specflow.json
#10 2.649 SpecFlowGeneratedFiles: Features/BE-Accounting.feature.cs
#10 2.649 SpecFlowGeneratedFiles: Features/BE-Contract.feature.cs
#10 2.649 SpecFlowGeneratedFiles: Features/BE-RelationManagement.feature.cs
#10 2.649 SpecFlowGeneratedFiles: Features/BE-Sales.feature.cs
#10 2.649 SpecFlowGeneratedFiles: Features/BE-Smoke.feature.cs
#10 5.627 Features/BE-Advanced.feature.cs : warning : For codebehind file 'Features/BE-Advanced.feature.cs', no feature file was found. [/app/MilesBelgiumRIA.csproj]
#10 5.973 AspectInjector|2.6.0: Found 0 aspects, 0 injections
#10 6.169 MilesBelgiumRIA -> /app/bin/Debug/net6.0/MilesBelgiumRIA.dll
#10 6.221
#10 6.221 Build succeeded.
#10 6.221
#10 6.221 Features/BE-Advanced.feature.cs : warning : For codebehind file 'Features/BE-Advanced.feature.cs', no feature file was found. [/app/MilesBelgiumRIA.csproj]
#10 6.221 1 Warning(s)
#10 6.221 0 Error(s)
#10 6.221
#10 6.221 Time Elapsed 00:00:05.46
#10 DONE 6.3s
#11 [ 7/10] RUN dotnet tool install --global Microsoft.Playwright.CLI
#11 2.575 Tools directory '/root/.dotnet/tools' is not currently on the PATH environment variable.
#11 2.575 If you are using bash, you can add it to your profile by running the following command:
#11 2.575
#11 2.575 cat << EOF >> ~/.bash_profile
#11 2.575 # Add .NET Core SDK tools
#11 2.575 export PATH="$PATH:/root/.dotnet/tools"
#11 2.575 EOF
#11 2.575
#11 2.575 You can add it to the current session by running the following command:
#11 2.575
#11 2.575 export PATH="$PATH:/root/.dotnet/tools"
#11 2.575
#11 2.579 You can invoke the tool using the following command: playwright
#11 2.579 Tool 'microsoft.playwright.cli' (version '1.2.3') was successfully installed.
#11 DONE 2.6s
#12 [ 8/10] WORKDIR /app/bin/Release/net6.0
#12 DONE 0.1s
#13 [ 9/10] RUN playwright install
#13 0.703 Couldn't find project using Playwright. Ensure a project or a solution exists in /app/bin/Release/net6.0, or provide another path using -p.
#13 ERROR: process "/bin/sh -c playwright install" did not complete successfully: exit code: 1
------
> [ 9/10] RUN playwright install:
0.703 Couldn't find project using Playwright. Ensure a project or a solution exists in /app/bin/Release/net6.0, or provide another path using -p.
------
Dockerfile:30
--------------------
28 | # Use the Playwright CLI tool to install the necessary browsers
29 | # Note: This step assumes the current working directory contains the necessary project context for Playwright
30 | >>> RUN playwright install
31 |
32 | # Run .NET tests using Playwright
--------------------
ERROR: failed to solve: process "/bin/sh -c playwright install" did not complete successfully: exit code: 1
Feel free to add any comments here that might help me, as I’m new to Docker and maybe this problem could be something simple for some of you.
Thank you very much!
2
Answers
Thanks for the explanation, I tried to rewrite the Dockerfile removing the second workdir, to use the /app only, but still getting the error below.
Log:
TLDR I think that your second
WORKDIR
command is causing the problem because you’re moving out of the project directory before installing Playwright. Remove that and your image should build. Below is a working setup that can be adapted for your project.It would be helpful to know what your project looks like, but assuming that it’s something like this:
The test client,
Program.cs
, is:Here’s a working
Dockerfile
:That will:
All of the files are copied into the
/app
working directory on the image, so there should be no issues with Playwright finding the project.