Like me, you may have almost definitely heard the unofficial rule of Docker: it is for light-weight, headless servers and command-line programs, no longer for graphical interfaces. Maximum people apply this rule for excellent reason why—CLI is what Docker was once constructed for. However what occurs while you spoil the foundations?
I made up our minds to do one thing out of the extraordinary. My purpose was once to run a full-fledged Linux desktop inside of a container. I do not want only a shell; I need a completely practical GUI that exists the place it is not intended to. That is what came about after I attempted.
Why am I doing this anyway?
It is only a little bit bit loopy
So why would somebody pass to all this bother to run Linux? In spite of everything, lets merely use VirtualBox and even dual-boot Linux along Home windows. My solution is unassuming: interest and the will for a problem.
I’ve been keen on Docker for a while, and whilst I’ve had revel in with full-stack internet construction, no longer a lot on the earth of Docker and containerization. I sought after to experiment with issues and be told via doing them, so this venture was once the solution.
From the beginning, I knew this would not be simple. I anticipated {that a} day, possibly two days at maximum, can be sufficient to get a graphical Linux machine up and operating. However the fact of the problem was once rather the other. The stumbling blocks I confronted over the following 4 days have been utterly sudden and way more complicated than I may have ever expected, stretching my endurance way past what I had ready for.
Earlier than diving into the technical main points, right here’s some context.
This complete experiment came about on a Home windows 10 PC, pushed via a particular query: what if you might want to have the most productive of each worlds? The theory of a complete Linux atmosphere operating inside of a Docker container, side-by-side with my same old Home windows programs, was once too intriguing to move up. No reboots, no separate walls—only a seamless, containerized Linux desktop.
So, first I needed to get my lab waiting. This intended putting in Docker and putting in WSL. With the groundwork laid, I refreshed my Docker fundamentals and skim its documentation. With this, my preliminary preparation was once whole; now, it was once time to position idea into observe.
Working my Docker container
I attempted doing this the laborious manner
My first try to run a Linux desktop in Docker was once, in hindsight, a rookie mistake out of overconfidence. I made up our minds to construct a customized symbol from scratch. In case you are new to Docker, a picture is a self-contained bundle of the whole thing an software must run. In order that after getting created a picture, it is going to run the similar all over, without reference to the {hardware} or working machine.
I made every other error proper from the beginning: I relied closely on an AI software to generate the code for my customized symbol.
Here is the hard earned lesson: If you do not perceive the era, do not copy-paste code identical to I did. I spent hours debugging mistakes without a transparent trail ahead, brute-forcing my manner by way of a large number of code I did not perceive.
After losing a complete day in this unproductive trail, I after all gave up and switched ways. My new way was once easy: I would use a pre-built symbol from Docker Hub. Call to mind Docker Hub as an “app retailer” for container pictures, full of answers created and shared via different builders. It was once a much-needed adjustment and after all allowed the actual paintings to start.
First Ray of Mild: The Just right Issues and the Dangerous Issues
After my failed customized symbol strive, I discovered a promising XFCE-based Debian symbol on Docker Hub. I downloaded it in mins and, with a couple of instructions, introduced it. After I opened the URL, I used to be greeted via a completely practical Linux desktop, operating proper in my browser. The natural geek pleasure of seeing a whole OS served from inside of a Docker container was once a sense I gained’t disregard. It labored!
The usability was once unusually respectable. LibreOffice and GIMP labored effective, despite the fact that there was once somewhat of a lag. I might estimate about 70% of local functionality, however nonetheless very usable. Firefox introduced, too, and I even attempted YouTube. That is after I hit the primary main hurdle: the colours have been uninteresting and washed out. A handy guide a rough take a look at showed my suspicion: the browser was once the usage of instrument rendering. My GPU was once sitting idle.
There was once every other downside I spotted: Flatpak did not paintings. Any try to set up an app from Flatpak failed with mistakes, so I needed to hotel to Debian programs. Regardless of those barriers, seeing a whole Linux desktop operating in my browser, served immediately from Docker, was once an enormous win.
Tweaking and studying
Could not assist myself
After a couple of mins with XFCE, I made up our minds to change issues up and take a look at GNOME as my desktop atmosphere. Giant mistake! It took hours of troubleshooting and error-fixing to get it operating, and when it after all introduced, it was once gradual and resource-hungry. In spite of everything, I swallowed my satisfaction and reverted to XFCE, and instructed myself, XFCE will not be flashy, however it’s way more responsive. So let’s lean in opposition to practicality.
With my new focal point on functionality, I made up our minds to revisit my first strive: development a customized symbol from scratch. This time, I studied the Dockerfile of the pre-built symbol I had used up to now. I sought after to know precisely what was once happening below the hood, and I sought after to peer if I may support the functionality myself. I experimented with a couple of new configurations, particularly attempting to make use of xrdp as a substitute of the noVNC forwarding way, to peer if a special protocol would provide a smoother revel in. However I did not see any distinction with xrdp.
To duplicate, create a record with the call “dockerfile”, paste the code, and run it.
FROM ubuntu:jammy-20230425
RUN apt replace &&
DEBIAN_FRONTEND=noninteractive apt set up -y
cinnamon locales sudo
tigervnc-standalone-server tigervnc-common
virtualgl mesa-utils mesa-vulkan-drivers
dbus-x11 xterm wget &&
locale-gen en_US.UTF-8 &&
update-locale LANG=en_US.UTF-8
# Create person
# Input the beneath username and passoword in xrdp login display
ARG USER=person
ARG PASS=1234
RUN useradd -m $USER -p $(openssl passwd $PASS) &&
usermod -aG sudo $USER &&
chsh -s /bin/bash $USER
# Setting for Cinnamon
RUN echo "#!/bin/shn
export XDG_SESSION_DESKTOP=cinnamonn
export XDG_SESSION_TYPE=x11n
export XDG_CURRENT_DESKTOP=X-Cinnamonn
export LIBGL_ALWAYS_INDIRECT=0n
exec cinnamon-session" > /house/$USER/.xinitrc &&
chown $USER:$USER /house/$USER/.xinitrc && chmod +x /house/$USER/.xinitrc
# Setup VNC password
RUN mkdir -p /house/$USER/.vnc &&
echo $PASS | vncpasswd -f > /house/$USER/.vnc/passwd &&
chmod 0600 /house/$USER/.vnc/passwd &&
chown -R $USER:$USER /house/$USER/.vnc
# Get started script
RUN echo "#!/bin/bashn
export DISPLAY=:1n
Xvnc :1 -geometry 1920x1080 -depth 24 -SecurityTypes VncAuth -rfbport 5901 -localhost no &n
sleep 2n
sudo -u $USER startx &n
tail -f /dev/null" > /get started && chmod +x /get started
EXPOSE 5901
CMD ["/start"]
Exploring Docker Hub
That is how I will have to’ve finished it from the beginning
If all of this seems like an excessive amount of paintings, there’s excellent information. You don’t must construct your personal symbol to get began or care for mistakes. My analysis led me to 2 improbable, ready-to-use answers that supply a a lot more streamlined revel in.
- Webtop via LinuxServer.io: This can be a nice open-source choice that gives quite a few Linux desktop flavors pre-packaged as Docker pictures. It makes use of noVNC to ship the desktop immediately in your browser, and the setup is simple.
- Kasm Workspaces: That is every other open-source choice for private use.
The advantage of those pictures is that they’ve the whole thing pre-configured, particularly Webtop. You merely pull the Docker symbol and run it. As soon as the container is operating, you’ll be able to get admission to your Linux via coming into the URL. I discovered the functionality to be significantly better than the rest I had attempted up to now, and, importantly, had audio pass-through, which I did not in finding with Kasm pictures.
To run Webtop, open Home windows CMD and paste this code
docker run -d ^
--name webtop-xfce ^
-e PUID=1000 ^
-e PGID=1000 ^
-e TZ=And so on/UTC ^
-p 3000:3000 ^
--shm-size=1gb ^
lscr.io/linuxserver/webtop:newest
I found out a couple of sudden perks
There are some advantages to this foolish setup
What began as a amusing venture to be told Docker and experiment with Linux boxes ended up revealing some unusually helpful options alongside the way in which. The most important discovery, and my private “aha!” second, was once figuring out the facility of far off desktop get admission to.
After I noticed a complete Linux desktop operating in my browser, I had a wild thought: what if I accessed it from a much less tough tool? I grabbed my Chromebook—a humble gadget with an Intel Celeron processor—opened the URL, and there it was once: the entire energy of my primary PC, streaming on my Chromebook. , I wasn’t chained to my table. I may proceed running from the sofa, or anyplace else in the home. My low-powered Chromebook become a high-performance window into my desktop, all because of a container.
For the most productive revel in, use a stressed Ethernet connection or a quick 5 GHz Wi-Fi community.
With the exception of this, I may see a number of different advantages:
- Disposable Sandboxes: I may check and spoil issues in a Linux atmosphere with none concern of messing up my primary OS. A really perfect playground for dangerous experiments.
- Personal Surfing: I will be able to spin up a brand new container, use a internet browser, after which delete all the atmosphere with a unmarried click on, leaving no hint at the back of.
- Devoted Workspaces: I will be able to create customized Linux pictures adapted to express duties—a distraction-free writing atmosphere, a coding setup with all my dev gear pre-installed.
This adaptability unfolded chances I hadn’t even regarded as when beginning the venture.
What’s subsequent?
My unfinished experiments
Whilst I had noticed for myself that operating a Linux desktop in Docker is conceivable, my adventure is not over. There have been a couple of experiments I sought after to do, however did not have time for it:
- Flatpak and Snap Retailer: I would love to determine how you can get those app shops running within the container to enlarge the instrument library.
- Gaming: With out the GPU passthrough, this would not be conceivable, however I am curious to determine an answer for this.
- Additional Optimization: I need to proceed tweaking the setup to peer if I will be able to squeeze out even higher functionality and scale back the enter lag.
Why is it tricky to run Linux in Docker?
The demanding situations
So, now that I’ve understood that operating a complete desktop atmosphere inside of a container and anticipating it to act like a typical desktop on Home windows is conceivable however painful, fragile, and a lot more bulky than operating a VM. The main causes for those are:
- Boxes don’t seem to be remoted Working Programs: Docker boxes proportion the host kernel. That is what makes them light-weight and nice for unmarried products and services. While desktop environments be expecting machine products and services like (systemd, logind, udev, DBus) and tool get admission to to be to be had. Boxes don’t supply that via default.
- No integrated show servers: Linux GUIs desire a compositor/show server (X11 or Wayland). A container does no longer supply one, so we need to do this ourselves.
- GPU get admission to: Boxes don’t virtualize GPUs via default, so that you should move tool nodes into the container. And on Home windows, there’s an extra WSL layer to move.
Used to be it definitely worth the bother?
Completely. This was once a amusing and deeply rewarding venture. I realized a ton in regards to the interior workings of Docker and Linux, and there’s a distinct more or less pleasure that comes from troubleshooting for hours and after all seeing your paintings repay.
So, would I like to recommend it? Sure, particularly in case you are curious and are on the lookout for a unusual weekend venture. However despite the fact that you might be no longer, the sensible advantages I found out—like far off desktop get admission to, disposable sandboxes, and devoted workspaces—make this way over an experiment. I will be able to see sensible use circumstances right here.
Even if the unofficial laws of Docker are there for a reason why, occasionally probably the most precious classes are discovered via breaking them. So, fan the flames of your terminal, grasp a pre-built symbol (or be courageous and construct your personal!), and spot the magic for your self. You may also in finding a couple of sudden perks alongside the way in which.


