.Net Core Dockerfile with Selenium Chrome Driver

Use .Net Core 2.2 as an example

FROM microsoft/dotnet:2.2-sdk

Use microsoft/dotnet:2.2-sdk as base image


Set current working directory

COPY ["MainApp/MainApp.csproj", "MainApp/"]
RUN dotnet restore "MainApp/MainApp.csproj"

Copy “.csproj” file to “MainApp” folder and restore packages

COPY . .

Copy everything in current directory into container “/src” folder

RUN dotnet publish "MainApp/MainApp.csproj" -c Release -o /app

Publish application in Release mode and set output folder to “/app”

RUN apt-get update
RUN apt-get install -y unzip xvfb libxi6 libgconf-2-4
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
RUN echo "deb [arch=amd64]  http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
RUN apt-get -y update
RUN apt-get -y install google-chrome-stable
RUN wget https://chromedriver.storage.googleapis.com/73.0.3683.68/chromedriver_linux64.zip
RUN unzip chromedriver_linux64.zip
RUN chmod +x chromedriver
Update container source and install required libraries.
Add google key and source into system source list and update.
Install google-chrome-stable library.
Download ChromeDriver from Google and unzip.
Grant execute permission to the file, which allows the application to run. Otherwise, you will see permission denied.
ENTRYPOINT ["dotnet", "/app/MainApp.dll"]

Add entry point to the application. Note: The current working directory will be “/src” when application running. So make sure the web driver is located in the “/src”

Leave a Reply

Your email address will not be published. Required fields are marked *