Difference between revisions of "MagicDraw in Docker"

From BITPlan Wiki
Jump to navigation Jump to search
Line 8: Line 8:
 
You need to be able to run a Java 6 Swing GUI in a container.
 
You need to be able to run a Java 6 Swing GUI in a container.
 
To get the GUI environment working might be tricky e.g. on MacOS see
 
To get the GUI environment working might be tricky e.g. on MacOS see
https://stackoverflow.com/questions/37826094/xt-error-cant-open-display-if-using-default-display
+
* https://stackoverflow.com/questions/37826094/xt-error-cant-open-display-if-using-default-display
  
 +
Please try out the following Dockerfile and Gui.java first using the build and run scripts.
 +
<source lang='bash'>
 +
./build
 +
./run
 +
</source>
 +
The Java based gui should appear:
 +
[[File:guitest.png|400px]]
 
== Dockerfile ==
 
== Dockerfile ==
 
<source lang='docker'>
 
<source lang='docker'>

Revision as of 18:10, 3 April 2019

How to run MagicDraw in Docker container

see also https://community.nomagic.com/running-magicdraw-in-a-docker-container-t5895.html

The goal is to get an older MagicDraw 16.9 working in a container. The following approach has been tested on Mac OS 10.13.6 High Sierra and Ubuntu 18.04 LTS Bionic Beaver.

Prerequisites

You need to be able to run a Java 6 Swing GUI in a container. To get the GUI environment working might be tricky e.g. on MacOS see

Please try out the following Dockerfile and Gui.java first using the build and run scripts.

./build
./run

The Java based gui should appear: Guitest.png

Dockerfile

FROM java:6
MAINTAINER Wolfgang Fahl (https://www.bitplan.com)

LABEL Description="Java GUI"

COPY src /home/root/java/src
WORKDIR /home/root/java

RUN mkdir bin
RUN javac -d bin src/Gui.java

WORKDIR /home/root/java/
ENTRYPOINT ["java", "-cp","bin","Gui"]

Gui.java

to be put in the src folder

import javax.swing.*;
import java.awt.event.*;

/**
 * 
 */
public class Gui {
public static class MyAction implements ActionListener {
public void actionPerformed(ActionEvent ae){
        JOptionPane.showMessageDialog(null, "Thanks.", "GUI Test", 1);
}
}
public static void main(String args[]){
        JFrame frame = new JFrame("GUI Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300,300);
        JButton button1 = new JButton("Click me");
        frame.getContentPane().add(button1);
        button1.addActionListener(new MyAction());

        frame.setVisible(true);
}
}

build

#!/bin/bash
# WF 2019-04-03
docker build . -t bitplan/javagui:latest

run

#!/bin/bash
# WF 2019-04-03
echo "DISPLAY=$DISPLAY"

# use socat for port 6000
port6000() {
  echo "checking port 6000"
  lsof -i TCP:6000
  if [ $? -ne 0 ]
  then
    socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"&
  fi
}

docker stop javagui
docker rm javagui
os=$(uname -a)
case $os in
  Linux*) 
   dockerdisplay=$DISPLAY
   n="--net=host"
   v="-v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/.Xauthority:/root/.Xauthority:rw";;
  Darwin*) 
   port6000
   dockerdisplay=docker.for.mac.host.internal:0
   v=""
   n="";;
esac
docker run  --name javagui -e DISPLAY=$dockerdisplay $n $v bitplan/javagui:latest
#docker exec -it javagui /bin/bash