How to run JavaFX on Docker

TL; DR

Install VcXsrv and add the following to your Dockerfile.

Command to add to Dockerfile


ENV DISPLAY host.docker.internal:0.0
RUN apt-get install openjfx

Introduction

I want to run a JavaFX application inside a Docker container!

I think many people think so. I am one of them.

At that time, I ran into some problems.

Here we will solve the above problem.

Build does not pass if only the base image of openjdk

You need to install the openjfx package.

Since Java 9, which was split into Oracle JDK and OpenJDK, OpenJDK no longer includes JavaFX packages. Originally, the openjdk package and openjfx package should be introduced in Sarah's base image, but the base image published by openjdk does not include the openjfx package.

The following description is required in the Dockerfile.

Install the openjfx package


RUN apt-get install openjfx

If you want to write it neatly, you should write it as follows.

Cleanly install the openjfx package


RUN apt-get update && \
    apt-get install -y --no-install-recommends \
      openjfx \
    && \
    rm -rf /var/lib/apt/lists/*

OpenJFX can not be used anymore · Issue #323 · docker-library/openjdk https://github.com/docker-library/openjdk/issues/323

rburgst/java8-openjfx-docker: openjdk8 container including openjfx https://github.com/rburgst/java8-openjfx-docker

I don't know how to get the GUI screen inside the container out of the container

The screen inside the container is displayed only inside the container. This means that it is usually impossible to see from outside the container.

But that's Docker, it's not doing nothing. There is a method to output the GUI screen inside the container to the outside of the container.

For details, refer to the following web page.

Install VcXsrv

Install VcXsrv.

This software is like an X-Server emulator and can display WSL GUI apps.

Display Linux GUI on Win10 with WSL and VcXsrv https://www.usagi1975.com/201903021706/

Setting the environment variable DISPLAY

The environment variable DISPLAY is the output destination of the GUI screen displayed by the x window system inside the container. Let's set this to host.docker.internal: 0.0.

Setting the environment variable DISPLAY


ENV DISPLAY host.docker.internal:0.0

Run GUI app inside Docker for windows container --FILES = 0 https://fileszero.kimurak.net/2019-04-18-docker-and-gui-on-windows/

DISPLAY-What are you going to do? https://sites.google.com/site/teyasn001/ubuntu-12-10/huan-jing-bian-shudisplay

Fly windows from local to remote X server-Qiita https://qiita.com/kkk627/items/8db34266722488eae412


In summary, the mechanism is as follows.

  1. Output the screen from the container to host.docker.internal: 0.0
  2. VcXsrv outside the container is the recipient of host.docker.internal: 0.0
  3. VcXsrv outputs GUI screen on the screen

in conclusion

The JavaFX app I created is made by Gradle, so it will be as follows.

Example


FROM gradle:5.5-jdk11

ENV DISPLAY host.docker.internal:0.0

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
      openjfx \
    && \
    rm -rf /var/lib/apt/lists/*

RUN git clone https://github.com/morichan/retuss.git

WORKDIR retuss

RUN gradle build

CMD ["gradle", "run"]

Please refer to it.

docker-images/retuss-docker at master · Morichan/docker-images https://github.com/Morichan/docker-images/tree/master/retuss-docker

Morichan/Retuss: Real-time Ensure Traceability between UML and Source-code System https://github.com/Morichan/Retuss

Recommended Posts

How to run JavaFX on Docker
How to run javafx with Raspberry Pi Posted on 2020/07/12
Steps to run docker on Mac
Run Embulk on Docker to convert files
How to run Blazor (C #) with Docker
How to install Docker
Run phpunit on Docker
How to run NullpoMino 7.5.0 on Ubuntu 20.04.1 64bit version
Run VS Code on Docker
Run openvpn on Docker (windows)
How to deploy on heroku
How to set Docker nginx
How to run Java EE Tutial on github on Eclipse
How to deploy jQuery on Rails
Run SSE (Server-Sent-Event) samples on docker
How to deploy Laravel on CentOS 7
How to run JUnit in Eclipse
Run puppeteer-core on Heroku (Docker edition)
How to run Ant in Gradle
[Java] How to update Java on Windows
How to install ImageMagick on Windows 10
How to use Ruby on Rails
To beginners launching Docker on AWS
Run React on a Docker container
Run the AWS CLI on Docker
Run GUI application on Docker container
How to use Bio-Formats on Ubuntu 20.04
How to run npm install on all projects in Lerna
How to install MariaDB 10.4 on CentOS 8
Rails on Tiles (how to write)
Run PureScript on a Docker container
[JavaFX] [Java8] How to use GridPane
How to install WildFly on Ubuntu 18.04
[Artifactory] How to use Docker repository
Deploy Rails on Docker to heroku
How to run React and Rails on the same server
How to build vim on Ubuntu 20.04
How to build CloudStack using Docker
How to start Camunda with Docker
How to run a mock server on Swagger-ui using stoplight/prism (using AWS/EC2/Docker)
How to run a job with docker login in AWS batch
How to check Java installed on Mac
A memorandum on how to use Eclipse
How to share files with Docker Toolbox
How to redo a deployment on Heroku
How to use Apache Derby on Eclipse
[Ruby on Rails] How to use CarrierWave
[Rails] How to use rails console with docker
How to detect microphone conflicts on Android
How to install Eclipse (Photon) on Mac
How to install production Metabase on Ubuntu
How to use Docker in VSCode DevContainer
How to switch Java versions on Mac
How to install beta php8.0 on CentOS8
How to change the timezone on Ubuntu
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
How to install kafkacat on Amazon Linux2
Until you run apache on ubuntu on docker
Understand in 5 minutes !! How to use Docker
Note: [Docker] How to start and stop