Can I run GUI apps in Docker?

I’m a noob and I’m quite lost here, and I’m starting to wondering if containers are for me. I’ve been trying to get a container going that will let me run a web browser in it, but I keep finding a lot of snake-oil howtos. For instance I tried but all it did was kick me out of my login session and wouldn’t let me log in again until I rebooted! I want to:

  1. Run a Docker container that will run a GUI app like a web browser
  2. Have it run through a VPN.
    I haven’t tried that last one yet, but it seems pretty straight-forward.

I’m doing all this in Ubuntu 22.04.
So like I said: are containers for me or should I book looking at virtualization?

You probably ran the container in privileged mode, at least that is when I had similar issues with systemd in a container. Otherwise containers can’t affect the host system that way.

If you need a web browser only, you can use special images that have RDP servers inside so you can connect to the RDP server through your browser and use the brower in the container too.

I wrote about it here and shared two examples to use that browser for accessing a service in another container which has no internet access.

You can run GUI apps in containers but that is not the main usecase of Docker containers. If you want containerized GUI apps, you can use other kind of containers like snap. In fact, when you install Firefox on Ubuntu, it is installed as a snap package.

Ok… I wasn’t expecting that. I thought snap was just another packaging system. I already use it for Firefox and Skype.
Googling “snap containers” gets a lot of hits with Amazon and Costco, but nothing that looks like it’ll run GUI apps.

I can recommend this guide

But I have never created my own snap package.

If you want to understand and confirm that snap runs containers, you can try this command after starting firefox (if installed as a snap package)

sudo nsenter -m -t $(pidof -s firefox) cat /etc/os-release

You will get Ubuntu Core as operating system and snapcraft as home url

NAME="Ubuntu Core"
PRETTY_NAME="Ubuntu Core 22"

But flatpk could also be an alternative