skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.

    # 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"
    
    # Playwright CLI tool to install the necessary browsers
    RUN playwright install chromium
    
    # Run .NET tests using Playwright
    RUN dotnet test --settings test.runsettings --filter "TestCategory=loginRIA"
    

    Log:

    2024/04/09 10:09:27 http2: server: error reading preface from client //./pipe/docker_engine: file has already been closed
    #0 building with "default" instance using docker driver
    
    #1 [internal] load build definition from Dockerfile
    #1 transferring dockerfile: 976B 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/9] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:e5a27c7f2a5f679f994106aa330585a7108e2812a8367e7686c13451e7fd27a0
    #4 DONE 0.0s
    
    #5 [internal] load build context
    #5 transferring context: 126.11kB 0.1s done
    #5 DONE 0.2s
    
    #6 [2/9] WORKDIR /app
    #6 CACHED
    
    #7 [3/9] COPY *.csproj ./
    #7 CACHED
    
    #8 [4/9] RUN dotnet restore
    #8 CACHED
    
    #9 [5/9] COPY . ./
    #9 DONE 0.8s
    
    #10 [6/9] RUN dotnet build
    #10 0.611 MSBuild version 17.3.2+561848881 for .NET
    #10 1.222   Determining projects to restore...
    #10 1.996   Restored /app/MilesBelgiumRIA.csproj (in 430 ms).
    #10 2.153   SpecFlowFeatureFiles: Features/BE-Accounting.feature;Features/BE-Contract.feature;Features/BE-RelationManagement.feature;Features/BE-Sales.feature;Features/BE-Smoke.feature
    #10 2.224   -> Using specflow.json
    #10 2.484   SpecFlowGeneratedFiles: Features/BE-Accounting.feature.cs
    #10 2.484   SpecFlowGeneratedFiles: Features/BE-Contract.feature.cs
    #10 2.484   SpecFlowGeneratedFiles: Features/BE-RelationManagement.feature.cs
    #10 2.484   SpecFlowGeneratedFiles: Features/BE-Sales.feature.cs
    #10 2.484   SpecFlowGeneratedFiles: Features/BE-Smoke.feature.cs
    #10 5.154 Features/BE-Advanced.feature.cs : warning : For codebehind file 'Features/BE-Advanced.feature.cs', no feature file was found. [/app/MilesBelgiumRIA.csproj]
    #10 5.493   AspectInjector|2.6.0: Found 0 aspects, 0 injections
    #10 5.668   MilesBelgiumRIA -> /app/bin/Debug/net6.0/MilesBelgiumRIA.dll
    #10 5.725 
    #10 5.725 Build succeeded.
    #10 5.725 
    #10 5.725 Features/BE-Advanced.feature.cs : warning : For codebehind file 'Features/BE-Advanced.feature.cs', no feature file was found. [/app/MilesBelgiumRIA.csproj]
    #10 5.725     1 Warning(s)
    #10 5.725     0 Error(s)
    #10 5.725 
    #10 5.725 Time Elapsed 00:00:05.02
    #10 DONE 5.8s
    
    #11 [7/9] RUN dotnet tool install --global Microsoft.Playwright.CLI
    #11 2.774 Tools directory '/root/.dotnet/tools' is not currently on the PATH environment variable.
    #11 2.774 If you are using bash, you can add it to your profile by running the following command:
    #11 2.774 
    #11 2.774 cat << EOF >> ~/.bash_profile
    #11 2.774 # Add .NET Core SDK tools
    #11 2.774 export PATH="$PATH:/root/.dotnet/tools"
    #11 2.774 EOF
    #11 2.774 
    #11 2.774 You can add it to the current session by running the following command:
    #11 2.774 
    #11 2.774 export PATH="$PATH:/root/.dotnet/tools"
    #11 2.774 
    #11 2.777 You can invoke the tool using the following command: playwright
    #11 2.777 Tool 'microsoft.playwright.cli' (version '1.2.3') was successfully installed.
    #11 DONE 2.8s
    
    #12 [8/9] RUN playwright install chromium
    #12 0.697 Microsoft.Playwright assembly was found, but is missing required assets. Please ensure to build your project before running Playwright tool.
    #12 ERROR: process "/bin/sh -c playwright install chromium" did not complete successfully: exit code: 1
    ------
     > [8/9] RUN playwright install chromium:
    0.697 Microsoft.Playwright assembly was found, but is missing required assets. Please ensure to build your project before running Playwright tool.
    ------
    Dockerfile:27
    --------------------
      25 |     
      26 |     # Playwright CLI tool to install the necessary browsers
      27 | >>> RUN playwright install chromium
      28 |     
      29 |     # Run .NET tests using Playwright
    --------------------
    ERROR: failed to solve: process "/bin/sh -c playwright install chromium" did not complete successfully: exit code: 1
    
    

  2. 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:

    ├── Dockerfile
    ├── obj
    │   ├── PlaywrightDemo.csproj.nuget.dgspec.json
    │   ├── PlaywrightDemo.csproj.nuget.g.props
    │   ├── PlaywrightDemo.csproj.nuget.g.targets
    │   ├── project.assets.json
    │   └── project.nuget.cache
    ├── PlaywrightDemo.csproj
    └── Program.cs
    

    The test client, Program.cs, is:

    using System;
    using System.Threading.Tasks;
    using Microsoft.Playwright;
    
    class Program
    {
        public static async Task Main()
        {
            using var playwright = await Playwright.CreateAsync();
            await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = true });
            var page = await browser.NewPageAsync();
            await page.GotoAsync("http://playwright.dev");
            Console.WriteLine(await page.TitleAsync());
        }
    }
    

    Here’s a working Dockerfile:

    FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
    
    RUN apt-get update -q && 
        apt-get install -y -qq --no-install-recommends 
            xvfb 
            libxcomposite1 
            libxdamage1 
            libatk1.0-0 
            libasound2 
            libdbus-1-3 
            libnspr4 
            libgbm1 
            libatk-bridge2.0-0 
            libcups2 
            libxkbcommon0 
            libatspi2.0-0 
            libnss3 
            libpango-1.0-0 
            libcairo2 
            libxrandr2
    
    WORKDIR /app
    
    COPY *.csproj .
    RUN dotnet restore
    
    COPY . .
    RUN dotnet build
    
    RUN dotnet tool install --global Microsoft.Playwright.CLI
    ENV PATH="${PATH}:/root/.dotnet/tools"
    RUN playwright install chromium
    
    CMD dotnet run
    

    That will:

    1. install all of the OS dependencies required for the Chrome browser;
    2. restore the C# project;
    3. build the C# project;
    4. install Playwright and the Chrome browser; and
    5. run the C# project.

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search