I've created service with .Net 6.0 using Playwright v1.19.1 and built an image on Ubuntu 20.04 as below:
sdk:6.0-focal AS build
runtime:6.0-focal AS runtime.
In the code I set up to launch the Chromium browser
await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false,
Channel = "chrome",
Args = new [] { "--disable-dev-shm-usage"}
});
Below is Docker file:
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
COPY . /app
WORKDIR /app
ENV PLAYWRIGHT_BROWSERS_PATH=/app/playwright
RUN dotnet restore "src/Service/Service.csproj"
RUN dotnet build "src/Service/Service.csproj" -c Release
RUN pwsh src/Service/bin/Release/net6.0/playwright.ps1 install chrome
RUN dotnet publish "src/Service/Service.csproj" -c Release -o /app/output
# =======================================================================================================
# Runtime
# =======================================================================================================
FROM mcr.microsoft.com/dotnet/runtime:6.0-focal AS runtime
EXPOSE 80
WORKDIR /home/site/wwwroot
COPY --from=build /app/output .
COPY --from=build /app/playwright .playwright/ms-playwright
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true \
PLAYWRIGHT_BROWSERS_PATH=/home/site/wwwroot/.playwright/ms-playwright
The image was built successful but when I start the image got below error. Do you know how to solve this issue? Thank you
Microsoft.Playwright.PlaywrightException: Browser closed.
==================== Browser output: ====================
<launching> /opt/google/chrome/chrome --disable-background-networking
--enable-features=NetworkService,NetworkServiceInProcess
--disable-background-timer-throttling --disable-backgrounding-occluded-windows
--disable-breakpad --disable-client-side-phishing-detection
--disable-component-extensions-with-background-pages
--disable-default-apps --disable-dev-shm-usage --disable-extensions
--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,
DestroyProfileOnBrowserClose,MediaRouter,AcceptCHFrame,AutoExpandDetailsElement
--allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection
--disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding
--disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run
--enable-automation --password-store=basic --use-mock-keychain
--no-service-autorun--export-tagged-pdf --no-sandbox --disable-dev-shm-usage
--user-data-dir=/tmp/playwright_chromiumdev_profile-HPOMeC
--remote-debugging-pipe --no-startup-window
<launched> pid=85
[pid=85][err] [85:85:0330/032427.114118:ERROR:ozone_platform_x11.cc(247)] Missing X server or $DISPLAY
[pid=85][err] [85:85:0330/032427.114193:ERROR:env.cc(225)] The platform failed to initialize. Exiting.
You need inside your container to set up a DISPLAY env parameter
so you will need to do in the container:
export DISPLAY='{IP}:0'
also start your browser with 'Headless = true',
also add --disable-gpu flag
if you want to run browser with GUI, remove the gpu flag and start your browser with 'Headless = false'
Related
I am trying to run a headless instance of chromium within an ubuntu docker image but I keep getting the error
this system has no display nor audio inputs or outputs
[0307/003516.533150:ERROR:bus.cc(393)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
Is there anyway to disable dbus as it seems docker does not support it
here are lines from my Dockerfile
FROM arm64v8/ubuntu:bionic
RUN apt install -y chromium-browser
RUN apt install -y chromium-drivers
Here is the launch line I use
chromium-browser --no-sandbox --headless --autoplay-policy=no-user-gesture-required --no-first-run --disable-gpu --use-fake-ui-for-media-stream --use-fake-device-for-media-stream --disable-sync index.html
To have real headless chromium you will need to add the --remote-debugging-port option to your line as follows:
chromium-browser --no-sandbox --headless --autoplay-policy=no-user-gesture-required --no-first-run --disable-gpu --use-fake-ui-for-media-stream --use-fake-device-for-media-stream --disable-sync --remote-debugging-port=9222 index.html
After launching, you can use the debugging port to connect and control the browser as described here
I'm getting below error when I run the cypress tests in Jenkins pipeline, but works fine locally. Should I set the appData in Dockerfile ? Is election missing write access ?
+ cypress run --browser chrome
[1m[47m[31mA JavaScript error occurred in the main process
[30mUncaught Exception:
**Error: Failed to get 'appData' path**
at App.c._setDefaultAppPaths (electron/js2c/browser_init.js:5:1300)
at Object.<anonymous> (electron/js2c/browser_init.js:185:2485)
at Object../lib/browser/init.ts (electron/js2c/browser_init.js:185:3714)
at __webpack_require__ (electron/js2c/browser_init.js:1:128)
Here's the Dockerfile.
ENV CI=1
ENV QT_X11_NO_MITSHM=1
ENV _X11_NO_MITSHM=1
ENV _MITSHM=0
# should be root user
RUN echo "whoami: $(whoami)"
RUN npm config -g set user $(whoami)
# command "id" should print:
# uid=0(root) gid=0(root) groups=0(root)
# which means the current user is root
RUN id
# point Cypress at the /root/cache no matter what user account is used
ENV CYPRESS_CACHE_FOLDER=/root/.cache/Cypress
RUN npm install -g "cypress#6.3.0"
RUN cypress verify
# Cypress cache and installed version
# should be in the root user's home folder
RUN cypress cache path
RUN cypress cache list
# give every user read access to the "/root" folder where the binary is cached
# we really only need to worry about the top folder, fortunately
RUN chmod 755 /root
CMD [ "cypress", "run"]
Here's the stage in jenkins;
stage('e2e cypress testing') {
steps {
withDockerContainer(args: '-v $PWD:/e2e -w /e2e', image: '<image name>') {
// some block
sh 'cypress-run'
}
}
}
Versions;
npm version: 6.14.11
Cypress package version: 6.3.0
Cypress binary version: 6.3.0
Electron version: 11.2.0
Bundled Node version: 12.18.3
This question already has answers here:
Error "The input device is not a TTY"
(16 answers)
docker error on windows : the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty' [duplicate]
(17 answers)
Closed 2 years ago.
I'm currently running the following command:
docker run -it -v $PWD:/e2e -w /e2e cypress/included:6.2.1
Error Message:
+ docker run -it -v %cd%:/e2e -w /e2e cypress/included:6.2.1
the input device is not a TTY
I'm pulling the cypress container from the Cypress Github Account
My bitbucket-pipelines.yaml file:
image: atlassian/default-image:2
pipelines:
default:
- step:
services:
- docker
script:
- docker run -it -v %cd%:/e2e -w /e2e cypress/included:6.2.1
My dockerfile:
FROM cypress/browsers:node12.18.3-chrome87-ff82
ENV CI=1
ENV QT_X11_NO_MITSHM=1
ENV _X11_NO_MITSHM=1
ENV _MITSHM=0
# should be root user
RUN echo "whoami: $(whoami)"
RUN npm config -g set user $(whoami)
# command "id" should print:
# uid=0(root) gid=0(root) groups=0(root)
# which means the current user is root
RUN id
# point Cypress at the /root/cache no matter what user account is used
# see https://on.cypress.io/caching
ENV CYPRESS_CACHE_FOLDER=/root/.cache/Cypress
RUN npm install -g "cypress#6.2.1"
RUN cypress verify
# Cypress cache and installed version
# should be in the root user's home folder
RUN cypress cache path
RUN cypress cache list
RUN cypress info
RUN cypress version
# give every user read access to the "/root" folder where the binary is cached
# we really only need to worry about the top folder, fortunately
RUN ls -la /root
RUN chmod 755 /root
# always grab the latest NPM and Yarn
# otherwise the base image might have old versions
RUN npm i -g yarn#latest npm#latest
# should print Cypress version
# plus Electron and bundled Node versions
RUN cypress version
RUN echo " node version: $(node -v) \n" \
"npm version: $(npm -v) \n" \
"yarn version: $(yarn -v) \n" \
"debian version: $(cat /etc/debian_version) \n" \
"user: $(whoami) \n" \
"chrome: $(google-chrome --version || true) \n" \
"firefox: $(firefox --version || true) \n"
ENTRYPOINT ["cypress", "run"]
If I run this command:
docker run -it -v %cd%:/e2e -w /e2e cypress/included:6.2.1
It will tell me that it cannot find my son file, and I don't why. Could someone help me a little bit?
What should I have to do? & Why I'm getting this issue, I guess I don't understand what is TTY means?
I have been set the "BUILD ENVIRONMENT VARIABLES" with the necessary variable, and added the hooks/build with:
#! /bin/bash
docker build \
--build-arg HBASE_VERSION="${HBASE_VERSION}" \
-f "${DOCKERFILE_PATH}" \
-t "${IMAGE_NAME}" .
Not are passing in build process, take a look in the log output:
Building in Docker Cloud's infrastructure...
Cloning into '.'...
Warning: Permanently added the RSA host key for IP address '192.30.253.113' to the list of known hosts.
Reset branch 'develop'
Your branch is up-to-date with 'origin/develop'.
KernelVersion: 4.4.0-1060-aws
Components: [{u'Version': u'18.03.1-ee-3', u'Name': u'Engine', u'Details': {u'KernelVersion': u'4.4.0-1060-aws', u'Os': u'linux', u'BuildTime': u'2018-08-30T18:42:30.000000000+00:00', u'ApiVersion': u'1.37', u'MinAPIVersion': u'1.12', u'GitCommit': u'b9a5c95', u'Arch': u'amd64', u'Experimental': u'false', u'GoVersion': u'go1.10.2'}}]
Arch: amd64
BuildTime: 2018-08-30T18:42:30.000000000+00:00
ApiVersion: 1.37
Platform: {u'Name': u''}
Version: 18.03.1-ee-3
MinAPIVersion: 1.12
GitCommit: b9a5c95
Os: linux
GoVersion: go1.10.2
Starting build of index.docker.io/rowupper/hbase-base:1.4.9...
Step 1/9 : FROM openjdk:8-jre-alpine3.9
---> b76bbdb2809f
Step 2/9 : RUN apk add --no-cache wget bash perl
---> Running in 50cf82a30723
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
Executing busybox-1.29.3-r10.trigger
OK: 130 MiB in 60 packages
Removing intermediate container 50cf82a30723
---> 108b5b9b6569
Step 3/9 : ARG HBASE_VERSION
---> Running in 5407a0bcbf60
Removing intermediate container 5407a0bcbf60
---> ea35e0967933
Step 4/9 : ENV HBASE_HOME=/usr/local/hbase HBASE_CONF_DIR=/etc/hbase PATH=${HBASE_HOME}/bin:$PATH
---> Running in 3a74e814acc8
Removing intermediate container 3a74e814acc8
---> 7a289348ba9b
Step 5/9 : WORKDIR $HBASE_HOME
Removing intermediate container e842d4658bf1
---> a6fede2510ec
Step 6/9 : RUN wget -O - https://archive.apache.org/dist/hbase/${HBASE_VERSION}/hbase-${HBASE_VERSION}-bin.tar.gz | tar -xz --strip-components=1 --no-same-owner --no-same-permissions
---> Running in 39b75bc77c5a
--2019-03-19 18:46:05-- https://archive.apache.org/dist/hbase//hbase--bin.tar.gz
Resolving archive.apache.org... 163.172.17.199
Connecting to archive.apache.org|163.172.17.199|:443...
connected.
HTTP request sent, awaiting response...
404 Not Found
2019-03-19 18:46:06 ERROR 404: Not Found.
tar: invalid magic
tar: short read
Removing intermediate container 39b75bc77c5a
The command '/bin/sh -c wget -O - https://archive.apache.org/dist/hbase/${HBASE_VERSION}/hbase-${HBASE_VERSION}-bin.tar.gz | tar -xz --strip-components=1 --no-same-owner --no-same-permissions' returned a non-zero code: 1
Is visible that the variable is missing, what I need do to solve this issue?
Could you try ARG and ENV, like
ARG HBASE_HOME="default_value"
ENV HBASE_HOME="$HBASE_HOME"
in your Dockerfile
build-arg VALUE should override the "default_value".
The hooks/build file need living in the same directory of Dockerfile.
My project has several subfolders, each folder with a Dockerfile.
I'm trying to build a docker image from a really simple project, just to start understanding how docker works and communicate. So, I have created a WebApi project, with just one method that returns a 200.
Once the project has been created, I created the dockerfile:
# TP5 for technology preview (will not be needed when we go GA)
# FROM microsoft/iis
FROM microsoft/iis:TP5
MAINTAINER Roman_Hervas
# Install Chocolatey (tools to automate commandline compiling)
ENV chocolateyUseWindowsCompression='false'
RUN #powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
# Install build tools
RUN powershell add-windowsfeature web-asp-net45 \
&& choco install microsoft-build-tools -y --allow-empty-checksums -version 14.0.23107.10 \
&& choco install dotnet4.6-targetpack --allow-empty-checksums -y \
&& choco install nuget.commandline --allow-empty-checksums -y \
&& nuget install MSBuild.Microsoft.VisualStudio.Web.targets -Version 14.0.0.3 \
&& nuget install WebConfigTransformRunner -Version 1.0.0.1
RUN powershell remove-item C:\inetpub\wwwroot\iisstart.*
# Copy files (temporary work folder)
RUN md c:\build
WORKDIR c:/build
COPY . c:/build
# Restore packages, build, copy
RUN nuget restore \
&& "c:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /p:Platform="Any CPU" /p:VisualStudioVersion=12.0 /p:VSToolsPath=c:\MSBuild.Microsoft.VisualStudio.Web.targets.14.0.0.3\tools\VSToolsPath WebApiDocker.sln \
&& xcopy c:\build\WebApiDocker\* c:\inetpub\wwwroot /s
# NOT NEEDED ANYMORE –> ENTRYPOINT powershell .\InitializeContainer
And the InitializeContainer:
If (Test-Path Env:\ASPNET_ENVIRONMENT)
{
\WebConfigTransformRunner.1.0.0.1\Tools\WebConfigTransformRunner.exe \inetpub\wwwroot\Web.config "\inetpub\wwwroot\Web.$env:ASPNET_ENVIRONMENT.config" \inetpub\wwwroot\Web.config
}
# prevent container from exiting
powershell
So, finally, I try to execute the command to build the project: docker build -t dockerexample .
The result is a failure with the following message (step 4):
Step 1/10 : FROM microsoft/iis:TP5
---> accd044753c1
Step 2/10 : MAINTAINER Roman_Hervas
---> Using cache
---> e42af9c57e0d
Step 3/10 : ENV chocolateyUseWindowsCompression 'false'
---> Using cache
---> 24621a9f18d9
Step 4/10 : RUN #powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((New-Object System.Net.WebClient).D
ownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
---> Running in 61199189917a
container 61199189917a0057fb54dddca6d80a6c6f9e8b77d2326379537684f58fefbe50 encountered an error during CreateContainer:
failure in a Windows system call: A connection could not be established with the Virtual Machine hosting the Container.
(0xc0370108) extra info: {"SystemType":"Container","Name":"61199189917a0057fb54dddca6d80a6c6f9e8b77d2326379537684f58fefb
e50","Owner":"docker","IsDummy":false,"IgnoreFlushesDuringBoot":true,"LayerFolderPath":"C:\\ProgramData\\Docker\\windows
filter\\61199189917a0057fb54dddca6d80a6c6f9e8b77d2326379537684f58fefbe50","Layers":[{"ID":"08b847bd-7f7e-5758-90be-43262
e170e22","Path":"C:\\ProgramData\\Docker\\windowsfilter\\64e43de6efd9eee001b12f6ed8add83d1aefff6cb5f8b55e9a44c4b1b2f27b8
0"},{"ID":"293472e6-599f-5a8e-b531-ac7499b0c900","Path":"C:\\ProgramData\\Docker\\windowsfilter\\cfb71fcbe2f95caa2a5306d
800c3d649067c00702a26a208ead6f5fed58e49c8"},{"ID":"baacc247-5374-5761-812f-e1ad911fda31","Path":"C:\\ProgramData\\Docker
\\windowsfilter\\89144a071d22e130e0ca9a069857a181b8976e9557c95395fb58116358dd5a02"},{"ID":"3d538ae4-eaf0-574c-b274-30bba
ce1a9b0","Path":"C:\\ProgramData\\Docker\\windowsfilter\\e2ff3bea019eaee94ab33312b6a39d6305b85df9b0b950680aa38e55eec5437
1"},{"ID":"937e8340-c320-5f09-a87e-9cd5912f40bb","Path":"C:\\ProgramData\\Docker\\windowsfilter\\0dd23a484fe7eea9da274be
8e6e1f0768b52a8a121e7bf274d5974ada02400d8"}],"HostName":"2ac70997c0f2","MappedDirectories":[],"SandboxPath":"C:\\Program
Data\\Docker\\windowsfilter","HvPartition":true,"EndpointList":["deb85df1-5dba-4394-a1ac-77f4a106e31a"],"HvRuntime":{"Im
agePath":"C:\\ProgramData\\Docker\\windowsfilter\\0dd23a484fe7eea9da274be8e6e1f0768b52a8a121e7bf274d5974ada02400d8\\Util
ityVM"},"Servicing":false,"AllowUnqualifiedDNSQuery":true}
I'm totally noob with Docker, so I have no idea of the problem here, and Google has not been too much helpful. My operating system is Windows 10 Pro, and Docker version is 17.03.1-ce-win12 (12058).
Question:
Why is it launching an error in step 4?
Thank you very much in advance.