Jena JavaScript custom functions scriptEngine null error - jena

Summary: I am trying to use the documentation on JavaScript SPARQL Functions to get a minimal working example of calling a custom javascript function, but it results in a scriptEngine null error.
Details: I setup a fuseki environment following the Docker instructions, so:
docker build --force-rm --build-arg JENA_VERSION=3.16.0 -t fuseki .
I then create a functions.js file per the documentation on JavaScript SPARQL Functions and launch the Docker container with:
docker run -i --rm -p "3030:3030" --name sparql1 -v `pwd`/functions.js:/functions.js -t fuseki --update --set arq:js-library=/functions.js --mem /ds
So far, so good. I have confirmed this works for simple update and queries, so the container appears sound. However, if I now create a query.rq file containing the example in the docs:
query=PREFIX js: <http://jena.apache.org/ARQ/jsFunction#>
SELECT ?input (js:toCamelCase(?input) AS ?X)
{
VALUES ?input { "some woRDs to PROCESS" }
}
and then proceed to dispatch this query to my container:
curl -X POST -d #query.rq localhost:3030/ds/query
then the console in which the container is running looks as follows:
% docker run -i --rm -p "3030:3030" --name sparql1 -v `pwd`/functions.js:/functions.js -t fuseki --update --set arq:js-library=/functions.js --mem /ds
[2022-03-09 16:47:20] INFO Server :: Apache Jena Fuseki 3.16.0
[2022-03-09 16:47:20] INFO Server :: Dataset Type: in-memory
[2022-03-09 16:47:20] INFO Server :: Path = /ds
[2022-03-09 16:47:20] INFO Server :: System
[2022-03-09 16:47:20] INFO Server :: Memory: 2.0 GiB
[2022-03-09 16:47:20] INFO Server :: Java: 17-ea
[2022-03-09 16:47:20] INFO Server :: OS: Linux 5.10.76-linuxkit amd64
[2022-03-09 16:47:20] INFO Server :: PID: 1
[2022-03-09 16:47:20] INFO Server :: Start Fuseki (port=3030)
[2022-03-09 16:47:23] INFO Fuseki :: [1] POST http://localhost:3030/ds/query
[2022-03-09 16:47:23] INFO Fuseki :: [1] Query = PREFIX js: <http://jena.apache.org/ARQ/jsFunction#>SELECT ?input (js:toCamelCase(?input) AS ?X){ VALUES ?input { "some woRDs to PROCESS" }}
[2022-03-09 16:47:24] WARN Fuseki :: [1] RC = 500 : Cannot invoke "javax.script.ScriptEngine.eval(java.io.Reader)" because "scriptEngine" is null
java.lang.NullPointerException: Cannot invoke "javax.script.ScriptEngine.eval(java.io.Reader)" because "scriptEngine" is null
at org.apache.jena.sparql.function.js.JSEngine.build(JSEngine.java:75) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.function.js.JSEngine.<init>(JSEngine.java:61) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.function.js.EnvJavaScript.build(EnvJavaScript.java:103) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.function.js.EnvJavaScript.<init>(EnvJavaScript.java:99) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.function.js.EnvJavaScript.create(EnvJavaScript.java:52) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.function.js.EnvJavaScript.get(EnvJavaScript.java:66) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.expr.E_Function.evalSpecial(E_Function.java:66) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.expr.ExprFunctionN.eval(ExprFunctionN.java:100) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.core.VarExprList.get(VarExprList.java:106) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.engine.iterator.QueryIterAssign.accept(QueryIterAssign.java:62) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.engine.iterator.QueryIterProcessBinding.hasNextBinding(QueryIterProcessBinding.java:69) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.engine.iterator.QueryIterConvert.hasNextBinding(QueryIterConvert.java:58) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:38) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:38) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.engine.ResultSetStream.hasNext(ResultSetStream.java:74) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.sparql.engine.ResultSetCheckCondition.hasNext(ResultSetCheckCondition.java:55) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.servlets.SPARQLQueryProcessor.executeQuery(SPARQLQueryProcessor.java:324) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.servlets.SPARQLQueryProcessor.execute(SPARQLQueryProcessor.java:273) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.servlets.SPARQLQueryProcessor.executeWithParameter(SPARQLQueryProcessor.java:222) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.servlets.SPARQLQueryProcessor.execute(SPARQLQueryProcessor.java:207) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.servlets.ActionService.executeLifecycle(ActionService.java:58) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.servlets.SPARQLQueryProcessor.execPost(SPARQLQueryProcessor.java:83) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.servlets.ActionProcessor.process(ActionProcessor.java:34) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.servlets.ActionBase.process(ActionBase.java:55) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.servlets.ActionExecLib.execAction(ActionExecLib.java:107) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.server.Dispatcher.dispatchAction(Dispatcher.java:115) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.server.Dispatcher.process(Dispatcher.java:107) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.server.Dispatcher.dispatch(Dispatcher.java:101) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.apache.jena.fuseki.servlets.FusekiFilter.doFilter(FusekiFilter.java:51) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1604) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:545) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1297) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1212) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.server.Server.handle(Server.java:500) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383) ~[jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547) [jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375) [jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270) [jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) [jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) [jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806) [jena-fuseki-server-3.16.0.jar:3.16.0]
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938) [jena-fuseki-server-3.16.0.jar:3.16.0]
at java.lang.Thread.run(Unknown Source) [?:?]
[2022-03-09 16:47:24] INFO Fuseki :: [1] 500 Cannot invoke "javax.script.ScriptEngine.eval(java.io.Reader)" because "scriptEngine" is null (212 ms)
It's at this point I'm totally lost ... why would scriptEngine be null here?

In Apache Jena 3.16.0, the JS engine was Nashorn. Nashorn was deprecated in Java 11 and removed in Java17.
An earlier Java version will have Hashorn in.
Now Jena version 4.4.0 uses the javascript engine of choice which has been added to the classpath, and hence needs to be in the dockerfile. Jena testing uses GraalVM.

I accepted the answer by #AndyS above because it helped me solve the problem. For anyone who comes across this and wants to know the full details I'm posting this additional detail.
Basically, I ignored the "official" docker compose script since it uses OpenJDK and instead created a simple Dockerfile based on one of the official GraalVM containers. I just needed to add the GraalVM nodejs so that it has a JavaScript interpreter, giving full Dockerfile as follows:
FROM ghcr.io/graalvm/graalvm-ce:ol8-java17-22.0.0.2-b2
RUN gu install nodejs
RUN curl -s -S --fail --location --max-redirs 3 https://repo1.maven.org/maven2/org/apache/jena/jena-fuseki-server/4.4.0/jena-fuseki-server-4.4.0.jar --output jena-fuseki-server-4.4.0.jar
RUN adduser -M fuseki
USER fuseki
EXPOSE 3030
ENTRYPOINT ["java", "-jar", "jena-fuseki-server-4.4.0.jar"]
CMD []
Now, you can build this with:
docker build -t fuseki .
And then run it and include the functions.js file from the original question with:
docker run -it --rm -p "3030:3030" --name sparql1 -v $(pwd)/functions.js:/functions.js fuseki --update --set arq:js-library=/functions.js --mem /ds
Now, posting the query from the question above gives the correct output:
% curl -X POST -d #query.rq localhost:3030/ds/query
{ "head": {
"vars": [ "input" , "X" ]
} ,
"results": {
"bindings": [
{
"input": { "type": "literal" , "value": "some woRDs to PROCESS" } ,
"X": { "type": "literal" , "value": "someWordsToProcess" }
}
]
}
}
Again, thanks to #AndyS without whose comment this full solution would have evaded me!

Related

How to solve the problem with starting devcontainer?

I tried to run devcontainer. Set up files:
devcontainer.json
{
"name": "C++",
"build": {
"dockerfile": "Dockerfile"
},
"features": {
"ghcr.io/devcontainers/features/git:1": {}
}
}
Dockerfile
FROM mcr.microsoft.com/devcontainers/cpp:0-debian-11
ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="3.22.2"
# Optionally install the cmake for vcpkg
COPY ./reinstall-cmake.sh /tmp/
RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
fi \
&& rm -f /tmp/reinstall-cmake.sh
But when i try to run devcontainer i get error:
[2022-12-23T18:57:44.771Z] ERROR: invalid character '\x00' looking for beginning of value
[2022-12-23T18:57:44.863Z] Stop (969 ms): Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f C:\Users\BOGUS_~1.NEW\AppData\Local\Temp\devcontainercli\container-features\0.25.2-1671821861765\Dockerfile-with-features -t vsc-test-9da7bcb89243449acfae569e26bf0e4b --target dev_containers_target_stage --build-context dev_containers_feature_content_source=C:\Users\BOGUS_~1.NEW\AppData\Local\Temp\devcontainercli\container-features\0.25.2-1671821861765 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp c:\Projects\docker_projects\Cpp\test\.devcontainer
[2022-12-23T18:57:44.865Z] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f C:\Users\BOGUS_~1.NEW\AppData\Local\Temp\devcontainercli\container-features\0.25.2-1671821861765\Dockerfile-with-features -t vsc-test-9da7bcb89243449acfae569e26bf0e4b --target dev_containers_target_stage --build-context dev_containers_feature_content_source=C:\Users\BOGUS_~1.NEW\AppData\Local\Temp\devcontainercli\container-features\0.25.2-1671821861765 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp c:\Projects\docker_projects\Cpp\test\.devcontainer
[2022-12-23T18:57:44.866Z] at Doe (c:\Users\Bogus_Kladik.NEW-PC\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:1894:1669)
[2022-12-23T18:57:44.866Z] at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
[2022-12-23T18:57:44.866Z] at async EF (c:\Users\Bogus_Kladik.NEW-PC\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:1893:1978)
[2022-12-23T18:57:44.866Z] at async uT (c:\Users\Bogus_Kladik.NEW-PC\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:1893:901)
[2022-12-23T18:57:44.866Z] at async Poe (c:\Users\Bogus_Kladik.NEW-PC\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:1899:2128)
[2022-12-23T18:57:44.867Z] at async Zf (c:\Users\Bogus_Kladik.NEW-PC\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:1899:3278)
[2022-12-23T18:57:44.867Z] at async aue (c:\Users\Bogus_Kladik.NEW-PC\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:2020:15276)
[2022-12-23T18:57:44.867Z] at async oue (c:\Users\Bogus_Kladik.NEW-PC\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:2020:15030)
[2022-12-23T18:57:44.882Z] Stop (5862 ms): Run: C:\Users\Bogus_Kladik.NEW-PC\AppData\Local\Programs\Microsoft VS Code\Code.exe --ms-enable-electron-run-as-node c:\Users\Bogus_Kladik.NEW-PC\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js up --user-data-folder c:\Users\Bogus_Kladik.NEW-PC\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --workspace-folder c:\Projects\docker_projects\Cpp\test --workspace-mount-consistency cached --id-label devcontainer.local_folder=c:\Projects\docker_projects\Cpp\test --log-level debug --log-format json --config c:\Projects\docker_projects\Cpp\test\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-12-23T18:57:44.882Z] Exit code 1
[2022-12-23T18:57:44.889Z] Command failed: C:\Users\Bogus_Kladik.NEW-PC\AppData\Local\Programs\Microsoft VS Code\Code.exe --ms-enable-electron-run-as-node c:\Users\Bogus_Kladik.NEW-PC\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js up --user-data-folder c:\Users\Bogus_Kladik.NEW-PC\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --workspace-folder c:\Projects\docker_projects\Cpp\test --workspace-mount-consistency cached --id-label devcontainer.local_folder=c:\Projects\docker_projects\Cpp\test --log-level debug --log-format json --config c:\Projects\docker_projects\Cpp\test\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-12-23T18:57:44.889Z] Exit code 1
How can I fix this problem?
Of the attempts, I can note the update of Docker Desktop, the update of wsl
The problem seems to be related to the use of BuildKit and Inline Cache in Docker.
The work-around suggested here is either:
To disable BuildKit in Docker:
Under Linux:
# in /etc/bash.bashrc
export DOCKER_BUILDKIT=0
Under Docker Dashboard:
Go to Settings > Docker Engine and set 'buildkit' to 'false':
"features": {
"buildkit": true
},
To disable the Inline Cache, either:
in the Dockerfile :
"args": {
"BUILDKIT_INLINE_CACHE": "0"
}
in the devcontainer.json:
"build": {
"dockerfile": "Dockerfile",
"args": {
"BUILDKIT_INLINE_CACHE": "0"
}
},
in the docker-compose.yml:
services:
app:
build:
context: .
dockerfile: Dockerfile
args:
BUILDKIT_INLINE_CACHE: 0

vscode .devcontainer and docker-compose version mismatch

I am trying to run a dev container on my vsode for ruby on rails, however, I cannot and getting the following error:
[2022-07-14T15:35:08.995Z] ERROR: Version mismatch: file /home/parham/projects/ruby/.devcontainer/docker-compose.yml specifies version 2.4 but extension file /tmp/docker-compose/docker-compose.devcontainer.build-1657812908036.yml uses version 1
[2022-07-14T15:35:09.136Z] Stop (1097 ms): Run: docker-compose --project-name ruby_devcontainer -f /home/parham/projects/ruby/.devcontainer/docker-compose.yml -f /tmp/docker-compose/docker-compose.devcontainer.build-1657812908036.yml build
[2022-07-14T15:35:09.669Z] Error: Command failed: docker-compose --project-name ruby_devcontainer -f /home/parham/projects/ruby/.devcontainer/docker-compose.yml -f /tmp/docker-compose/docker-compose.devcontainer.build-1657812908036.yml build
[2022-07-14T15:35:09.669Z] at Uu (/home/parham/.vscode-remote-containers/dist/dev-containers-cli-0.241.3/dist/spec-node/devContainersSpecCLI.js:204:419)
[2022-07-14T15:35:09.669Z] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2022-07-14T15:35:09.670Z] at async kR (/home/parham/.vscode-remote-containers/dist/dev-containers-cli-0.241.3/dist/spec-node/devContainersSpecCLI.js:204:2335)
[2022-07-14T15:35:09.670Z] at async DR (/home/parham/.vscode-remote-containers/dist/dev-containers-cli-0.241.3/dist/spec-node/devContainersSpecCLI.js:188:2228)
[2022-07-14T15:35:09.670Z] at async QR (/home/parham/.vscode-remote-containers/dist/dev-containers-cli-0.241.3/dist/spec-node/devContainersSpecCLI.js:245:2177)
[2022-07-14T15:35:09.670Z] at async cb (/home/parham/.vscode-remote-containers/dist/dev-containers-cli-0.241.3/dist/spec-node/devContainersSpecCLI.js:245:3110)
[2022-07-14T15:35:09.670Z] at async i_ (/home/parham/.vscode-remote-containers/dist/dev-containers-cli-0.241.3/dist/spec-node/devContainersSpecCLI.js:245:13194)
[2022-07-14T15:35:09.670Z] at async n_ (/home/parham/.vscode-remote-containers/dist/dev-containers-cli-0.241.3/dist/spec-node/devContainersSpecCLI.js:245:12950)
[2022-07-14T15:35:09.682Z] Stop (6372 ms): Run in Host: /home/parham/.vscode-server/bin/92d25e35d9bf1a6b16f7d0758f25d48ace11e5b9/node /home/parham/.vscode-remote-containers/dist/dev-containers-cli-0.241.3/dist/spec-node/devContainersSpecCLI.js up --workspace-folder /home/parham/projects/ruby --workspace-mount-consistency cached --id-label devcontainer.local_folder=/home/parham/projects/ruby --log-level debug --log-format json --config /home/parham/projects/ruby/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-07-14T15:35:09.684Z] Exit code 1
[2022-07-14T15:35:09.689Z] Command failed: /home/parham/.vscode-server/bin/92d25e35d9bf1a6b16f7d0758f25d48ace11e5b9/node /home/parham/.vscode-remote-containers/dist/dev-containers-cli-0.241.3/dist/spec-node/devContainersSpecCLI.js up --workspace-folder /home/parham/projects/ruby --workspace-mount-consistency cached --id-label devcontainer.local_folder=/home/parham/projects/ruby --log-level debug --log-format json --config /home/parham/projects/ruby/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-07-14T15:35:09.689Z] Exit code 1
UPDATE
This is my .devcotnainer.json which forwards some ports and they are the only changes that I have added to the code.
{
"name": "Ruby on Rails & Postgres",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
"customizations": {
"vscode": {
"extensions": [
"rebornix.Ruby"
]
}
},
"forwardPorts": ["30000:3000", "54320:5432"],
"remoteUser": "vscode",
"features": {
"git": "latest",
"python": "latest"
}
}
If you would like to reproduce select all additional features. That will cause error.

Cannot launch Playwright in Ubuntu Docker image with .NET

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'

How to bind mounted persistent volumes on docker ? I'm trying to run Sonarqube on docker

I want to run SonarQube on docker. When I run the whiteout volume persist option, it works properly with this command:
docker run -d --name sonarqube -p 9000:9000 sonarqube
But when I try to set bind-mounted persistent volumes, my docker doesn't start. The docker command used is:
docker run -d --name sonarqube \
-p 9000:9000 \
-v /opt/docker-mounts/sonaarqube/conf:/opt/sonarqube/conf \
-v /opt/docker-mounts/sonaarqube/data:/opt/sonarqube/data \
-v /opt/docker-mounts/sonaarqube/logs:/opt/sonarqube/logs \
-v /opt/docker-mounts/sonaarqube/extensions:/opt/sonarqube/extensions \
sonarqube
Note: I run docker command with root privilege.
I use this SonarQube image from Docker Hub: https://hub.docker.com/_/sonarqube?tab=description
I get this Error in docker logs :
>
06:42:37.293 [main] WARN org.sonar.application.config.AppSettingsLoaderImpl - Configuration file not found: /opt/sonarqube/conf/sonar.properties
2019.07.07 06:42:37 INFO app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2019.07.07 06:42:37 INFO app[][o.s.a.es.EsSettings] Elasticsearch listening on /127.0.0.1:9001
2019.07.07 06:42:37 INFO app[][o.s.a.ProcessLauncherImpl] Launch process[[key='es', ipcIndex=1, logFilenamePrefix=es]] from [/opt/sonarqube/elasticsearch]: /opt/sonarqube/elasticsearch/bin/elasticsearch
2019.07.07 06:42:38 INFO app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
2019.07.07 06:42:38 INFO app[][o.e.p.PluginsService] no modules loaded
2019.07.07 06:42:38 INFO app[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2019-07-07 06:42:41,143 main ERROR Unable to create file /opt/sonarqube/logs/es.log java.io.IOException: Permission denied
at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.base/java.io.File.createNewFile(File.java:1024)
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:628)
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:608)
at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:113)
at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:114)
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:188)
at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:145)
at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:61)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:123)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:234)
at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:127)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:302)
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159)
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93)
2019-07-07 06:42:41,148 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile: java.lang.IllegalStateException: ManagerFactory [org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory#5dcd8c7a] unable to create manager for [/opt/sonarqube/logs/es.log] with data [org.apache.logging.log4j.core.appender.rolling.RollingFileManager$FactoryData#2250b9f2[pattern=/opt/sonarqube/logs/es.%d{yyyy-MM-dd}.log, append=true, bufferedIO=true, bufferSize=8192, policy=CompositeTriggeringPolicy(policies=[TimeBasedTriggeringPolicy(nextRolloverMillis=0, interval=1, modulate=true)]), strategy=DefaultRolloverStrategy(min=-2147483648, max=2147483647, useMax=false), advertiseURI=null, layout=%d{yyyy.MM.dd HH:mm:ss} %-5level es[][%logger{1.}] %msg%n, filePermissions=null, fileOwner=null]] java.lang.IllegalStateException: ManagerFactory [org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory#5dcd8c7a] unable to create manager for [/opt/sonarqube/logs/es.log] with data [org.apache.logging.log4j.core.appender.rolling.RollingFileManager$FactoryData#2250b9f2[pattern=/opt/sonarqube/logs/es.%d{yyyy-MM-dd}.log, append=true, bufferedIO=true, bufferSize=8192, policy=CompositeTriggeringPolicy(policies=[TimeBasedTriggeringPolicy(nextRolloverMillis=0, interval=1, modulate=true)]), strategy=DefaultRolloverStrategy(min=-2147483648, max=2147483647, useMax=false), advertiseURI=null, layout=%d{yyyy.MM.dd HH:mm:ss} %-5level es[][%logger{1.}] %msg%n, filePermissions=null, fileOwner=null]]
at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:115)
at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:114)
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:188)
at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:145)
at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:61)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:123)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:234)
at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:127)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:302)
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159)
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93)
2019-07-07 06:42:41,152 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:235)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:135)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:234)
at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:127)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:302)
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159)
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93)
2019-07-07 06:42:41,154 main ERROR Null object returned for RollingFile in Appenders.
2019-07-07 06:42:41,154 main ERROR Unable to locate appender "file_es" for logger config "root"
2019.07.07 06:42:41 WARN app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [es]: 1
2019.07.07 06:42:41 INFO app[][o.s.a.SchedulerImpl] Process[es] is stopped
2019.07.07 06:42:41 INFO app[][o.s.a.SchedulerImpl] SonarQube is stopped
I think you have persistented the volumes but there is no file and required permissions. Follow below steps.
Start the container without persistent volume
$ docker run -d --name sonarqube -p 9000:9000 sonarqube
$ docker ps -f name=sonarqube
Note down the container id.
Copy folders from the container to host directory
$ cd /opt/docker-mounts/sonaarqube
$ chown -R 999:999 .
$ docker cp -a CONTAINER_ID:/opt/sonarqube/conf .
$ docker cp -a CONTAINER_ID:/opt/sonarqube/logs . # this can be skipped is not required
$ docker cp -a CONTAINER_ID:/opt/sonarqube/data . # optional, if you need the existing data from the container
$ docker cp -a CONTAINER_ID:/opt/sonarqube/extensions .
Now start the container with persistent volumes
$ docker run -d --name sonarqube \
-p 9000:9000 \
-v /opt/docker-mounts/sonaarqube/conf:/opt/sonarqube/conf \
-v /opt/docker-mounts/sonaarqube/data:/opt/sonarqube/data \
-v /opt/docker-mounts/sonaarqube/logs:/opt/sonarqube/logs \
-v /opt/docker-mounts/sonaarqube/extensions:/opt/sonarqube/extensions \
sonarqube

Docker hub automated build falling with missing variable

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.

Resources