MagicDraw in Docker


Wolfgang Fahl

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.

The first step is to try the Prerequisites. In this step we try out to get a Java Swing GUI to work in a Docker container. If this works our chances are high that the docker container for Magicdraw will also work.

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

How to run MagicDraw in Docker container[edit]

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.

The first step is to try the Prerequisites. In this step we try out to get a Java Swing GUI to work in a Docker container. If this works our chances are high that the docker container for Magicdraw will also work.

Prerequisites[edit]

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[edit]

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[edit]

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[edit]

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

run[edit]

This run script tries to make the X11 environment of your host computer available to your docker container. The approach is slightly different on Linux and MacOS. This has not been tested on Windows due to the need of an X11 environment. According to https://blogs.msdn.microsoft.com/jamiedalton/2018/05/17/windows-10-docker-gui/ you might have some success with Xming in this environment. Please let me know whether this works via http://www.bitplan.com/index.php/Contact.

#!/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

Dockerfile[edit]

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[edit]

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[edit]

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

run[edit]

This run script tries to make the X11 environment of your host computer available to your docker container. The approach is slightly different on Linux and MacOS. This has not been tested on Windows due to the need of an X11 environment. According to https://blogs.msdn.microsoft.com/jamiedalton/2018/05/17/windows-10-docker-gui/ you might have some success with Xming in this environment. Please let me know whether this works via http://www.bitplan.com/index.php/Contact.

#!/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

magicdraw 16[edit]

You need a MD_UML_169_no_install.zip which you can download from the No Magic magicdraw website.

The run script includes a mount

-v $HOME/:/home/$USER

which will make your home directory available inside the docker container. This way you can select your license key file and the models you'd like to open.

Dockerfile[edit]

# see http://wiki.bitplan.com/index.php?title=MagicDraw_in_Docker
FROM ubuntu:12.04
MAINTAINER Wolfgang Fahl (https://www.bitplan.com)

LABEL Description="Java Magicdraw"

# make unzip available
# make vim available (to be able to edit configuration files with bash)
# make libraries for java available
# https://askubuntu.com/questions/674579/libawt-xawt-so-libxext-so-6-cannot-open-shared-object-file-no-such-file-or-di

RUN apt-get update&&apt-get install -y vim unzip libxrender1 libxtst6 libxi6

# Install Java.
# https://askubuntu.com/a/1026336/129227
ADD jdk-6u20-linux-x64.bin /usr/local/src
ADD installjava /usr/local/src

WORKDIR /usr/local/src
RUN ./installjava

# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-6-oracle

# get the magicdraw sources
ADD MD_UML_169_no_install.zip /home/root/java/md/

WORKDIR /home/root/java/md

RUN unzip /home/root/java/md/MD_UML_169_no_install.zip

# Make sure you have the your license file available
ADD MagicDraw_16_9_Enterprise_Mobile_key.txt /home/root/java/md

# start Magicdraw
ENTRYPOINT ["bin/mduml"]

installjava[edit]

#/bin/bash
# WF 2019-06-04
# see https://askubuntu.com/a/1026336/129227
# revised from https://dzone.com/articles/installing-oracle-java6-ubuntu
# 1. we expect the oracle bin file in /usr/local/src
cd /usr/local/src
# 2. Make the download bin file executable
chmod +x jdk-6u20-linux-x64.bin
# 3. Extract the bin file.
echo "yes" | ./jdk-6u20-linux-x64.bin
# 4. Using the following command create a folder called "jvm" inside /usr/lib if it does not already exist.
mkdir -p /usr/lib/jvm
# 5. Move the extracted folder into the newly created jvm folder.
java6=/usr/lib/jvm/java-6-oracle
mv jdk1.6.0_20 $java6
# 6. To install the Java source run the following commands.
update-alternatives --install /usr/bin/javac javac $java6/bin/javac 1
update-alternatives --install /usr/bin/java java $java6/bin/java 1
update-alternatives --install /usr/bin/javaws javaws $java6/bin/javaws 1
# 7. To make this default java:
update-alternatives --config javac
update-alternatives --config java
update-alternatives --config javaws
# 8. To make symlinks point to the new Java location run the following command.
ls -la /etc/alternatives/java*

build[edit]

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

run[edit]

#!/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
}
imagename=md16o
containername=$imagename
echo "stopping $containername"
docker stop $containername
echo "removing $containername"
docker rm $containername
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
   # allow access from localhost
   xhost + 127.0.0.1
   dockerdisplay=host.docker.internal:0
   v=""
   n="";;
esac
docker run  --name $containername -e DISPLAY=$dockerdisplay $n $v -v $HOME/:/home/$USER bitplan/$imagename:latest

Dockerfile[edit]

# see http://wiki.bitplan.com/index.php?title=MagicDraw_in_Docker
FROM ubuntu:12.04
MAINTAINER Wolfgang Fahl (https://www.bitplan.com)

LABEL Description="Java Magicdraw"

# make unzip available
# make vim available (to be able to edit configuration files with bash)
# make libraries for java available
# https://askubuntu.com/questions/674579/libawt-xawt-so-libxext-so-6-cannot-open-shared-object-file-no-such-file-or-di

RUN apt-get update&&apt-get install -y vim unzip libxrender1 libxtst6 libxi6

# Install Java.
# https://askubuntu.com/a/1026336/129227
ADD jdk-6u20-linux-x64.bin /usr/local/src
ADD installjava /usr/local/src

WORKDIR /usr/local/src
RUN ./installjava

# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-6-oracle

# get the magicdraw sources
ADD MD_UML_169_no_install.zip /home/root/java/md/

WORKDIR /home/root/java/md

RUN unzip /home/root/java/md/MD_UML_169_no_install.zip

# Make sure you have the your license file available
ADD MagicDraw_16_9_Enterprise_Mobile_key.txt /home/root/java/md

# start Magicdraw
ENTRYPOINT ["bin/mduml"]

installjava[edit]

#/bin/bash
# WF 2019-06-04
# see https://askubuntu.com/a/1026336/129227
# revised from https://dzone.com/articles/installing-oracle-java6-ubuntu
# 1. we expect the oracle bin file in /usr/local/src
cd /usr/local/src
# 2. Make the download bin file executable
chmod +x jdk-6u20-linux-x64.bin
# 3. Extract the bin file.
echo "yes" | ./jdk-6u20-linux-x64.bin
# 4. Using the following command create a folder called "jvm" inside /usr/lib if it does not already exist.
mkdir -p /usr/lib/jvm
# 5. Move the extracted folder into the newly created jvm folder.
java6=/usr/lib/jvm/java-6-oracle
mv jdk1.6.0_20 $java6
# 6. To install the Java source run the following commands.
update-alternatives --install /usr/bin/javac javac $java6/bin/javac 1
update-alternatives --install /usr/bin/java java $java6/bin/java 1
update-alternatives --install /usr/bin/javaws javaws $java6/bin/javaws 1
# 7. To make this default java:
update-alternatives --config javac
update-alternatives --config java
update-alternatives --config javaws
# 8. To make symlinks point to the new Java location run the following command.
ls -la /etc/alternatives/java*

build[edit]

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

run[edit]

#!/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
}
imagename=md16o
containername=$imagename
echo "stopping $containername"
docker stop $containername
echo "removing $containername"
docker rm $containername
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
   # allow access from localhost
   xhost + 127.0.0.1
   dockerdisplay=host.docker.internal:0
   v=""
   n="";;
esac
docker run  --name $containername -e DISPLAY=$dockerdisplay $n $v -v $HOME/:/home/$USER bitplan/$imagename:latest
🖨 🚪