Skip to content

Instantly share code, notes, and snippets.

@lukaszlach
Last active June 11, 2021 09:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaszlach/057dd97e18afb67efdb8d426f8d9bf27 to your computer and use it in GitHub Desktop.
Save lukaszlach/057dd97e18afb67efdb8d426f8d9bf27 to your computer and use it in GitHub Desktop.

Docker Masters Live - X

Łukasz Lach, Docker Captain | 2021

https://lach.dev/ | https://github.com/lukaszlach/

https://www.dockermasters.pl/

X

Install X Server (Windows and Mac)

Prepare X environment (Windows and Mac)

DISPLAY=:0 /usr/X11/bin/xhost + 127.0.0.1
export DISPLAY=host.docker.internal:0

Try running xhost if direct /usr/X11/bin/xhost does not work for you.

Prepare X environment (Linux)

Check if you have the DISPLAY environment variable set:

env | grep DISPLAY

Set it if needed:

export DISPLAY=:0

Eyes on the first example

Windows and Mac:

docker run --rm -e DISPLAY alpine:3.12 sh -c 'apk -U add xeyes && xeyes'

Linux:

docker run --rm -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix alpine:3.12 sh -c 'apk -U add xeyes && xeyes'

Ready examples

https://github.com/jessfraz/dockerfiles

docker run -e DISPLAY jess/tor-browser
docker run -e DISPLAY jess/wireshark
docker run -e DISPLAY jess/libreoffice
docker run -e DISPLAY jess/firefox

C:\>

Dockerfile

FROM ubuntu:20.04
CMD ["dosbox"]
VOLUME /dosbox
RUN apt-get update && \
    apt-get install -y dosbox
RUN export CONF=$(dosbox -printconf) && \
    sed -i 's/^usescancodes=.*/usescancodes=false/g' "$CONF" && \
    echo 'MOUNT C /dosbox' >> "$CONF" && \
    echo 'C:' >> "$CONF"

Play it

https://gamesnostalgia.com/ | https://www.dosgamesarchive.com/

docker build -t dosbox .
docker run -it -e DISPLAY -v $(pwd)/games:/dosbox dosbox

Parseltongue

main.py

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

window = Gtk.Window(title="Hello World")
window.set_border_width(20)
window.set_size_request(300, 150)

button1 = Gtk.Button("Hello from Docker!")
window.add(button1)

window.show_all()
window.connect("destroy", Gtk.main_quit)
Gtk.main()

Dockerfile

FROM debian:buster
CMD ["python3", "/main.py"]
RUN apt-get update && \
    apt-get install -y \
      python3-gi python3-gi-cairo gir1.2-gtk-3.0
COPY main.py /

Run it

docker build -t python-gui .
docker run -e DISPLAY python-gui

Debug containers with GUI

Run it

docker run -d --name web -p 80:80 nginx:1.19
docker run --rm -it -e DISPLAY --net container:web --cap-add NET_ADMIN jess/wireshark

Set Wireshark packet filter to tcp.port == 80 || udp.port == 80 and run curl localhost.

PHPStorm

Build it

docker build -t phpstorm http://lach.dev/phpstorm

http://lach.dev/phpstorm

Run it

docker run -it --name phpstorm -e DISPLAY -v $(pwd)/project:/home phpstorm

Start anytime

docker start phpstorm

Play with the image

docker build -t ubuntu-desktop --target ubuntu-desktop http://lach.dev/phpstorm

Start Xfce Desktop in Docker:

docker run --rm -it -e DISPLAY ubuntu-desktop startxfce4

Install and run GIMP in Docker:

docker run --rm -it -e DISPLAY ubuntu-desktop \
    bash -c 'apt-get update && apt-get install -y gimp && gimp'

Debug container processes with a GUI tool:

docker run --rm -it -e DISPLAY --pid container:web ubuntu-desktop \
    bash -c 'apt-get update && apt-get install -y stacer && stacer'
docker run --rm -it -e DISPLAY --pid container:web ubuntu-desktop \
    bash -c 'apt-get update && apt-get install -y gnome-system-monitor && gnome-system-monitor'

Come get some!

Build it

http://lach.dev/duke-nukem-3d

docker build -t duke-nukem-3d http://lach.dev/duke-nukem-3d

Play it

Build and run the game on VNC port 5900:

docker run -v $(pwd)/wine:/root/.wine -p 5900:5900 duke-nukem-3d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment