Łukasz Lach, Docker Captain | 2021
https://lach.dev/ | https://github.com/lukaszlach/
Install X Server (Windows and Mac)
- VcXsrv (Windows) - https://sourceforge.net/projects/vcxsrv/
- XQuartz (Mac) - https://www.xquartz.org/
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
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
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
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
.
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'
Play it
Build and run the game on VNC port 5900:
docker run -v $(pwd)/wine:/root/.wine -p 5900:5900 duke-nukem-3d