How to open Ubuntu GUI inside a Docker image

UbuntuDockerDocker Image

Ubuntu Problem Overview


I have downloaded the Ubuntu image inside Docker on Windows.

I can run Ubuntu by:

docker run -it ubuntu

I only see root, but I don't see the Ubuntu GUI. How do I install or configure the GUI for that image and run applications on that GUI like we run in a VM?

Ubuntu Solutions


Solution 1 - Ubuntu

fcwu/docker-ubuntu-vnc-desktop

https://github.com/fcwu/docker-ubuntu-vnc-desktop provides a convenient setup:

sudo docker run --name ubvnc -p 6080:80 -p 5900:5900 dorowu/ubuntu-desktop-lxde-vnc:bionic

Then on host either:

enter image description here

To quit just kill docker on the terminal. And to restart the machine:

sudo docker start ubvnc

and then reconnect with VNC. Then to quit the machine:

sudo docker stop ubvnc

You have to wait a few seconds for the VNC server on the guest to start before you can connect.

Chromium inside the guest won't start from the menu. If you try to launch it from the command line it explains why:

Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

so just run it from the CLI with:

chromium-browser --no-sandbox

Firefox does not care however.

TODO: no audio. --device /dev/snd did not help:

EDIT: they added a section for it: https://github.com/fcwu/docker-ubuntu-vnc-desktop/tree/e4922ce92f945fc482994b7a0fd95ca5de7295b3#sound-preview-version-and-linux-only

See also:

Tested on:

  • Ubuntu 19.04 host, fcwu/docker-ubuntu-vnc-desktop, dorowu/ubuntu-desktop-lxde-vnc image id: 70516b87e92d.

  • Ubuntu 21.10 host, dorowu/ubuntu-desktop-lxde-vnc:focal (Ubuntu 20.04)

Solution 2 - Ubuntu

Generally, the approach for developing with Docker is to keep the IDE on the workstation, and build images with the binary produced from the sources.

You can find many example of such a workflow (local compilation, deployment in Docker containers) in domeide.github.io/ (Docker meets the IDE!)
For example: Docker Tools for VisualStudio allows for a tight integration between your editor and Docker processes.

https://microsoftcloudexplorer.gallerycdn.vsassets.io/extensions/microsoftcloudexplorer/visualstudiotoolsfordocker-preview/0.41.0/1478598789732/205468/1/add-docker-support.png

(But this is for Visual Studio 2015, not Visual Studio Code.)

Solution 3 - Ubuntu

You can directly connect a Docker container to your X server.

See Stack Overflow question https://stackoverflow.com/questions/16296753/can-you-run-gui-applications-in-a-docker-container/25280523#25280523.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionShan KhanView Question on Stackoverflow
Solution 1 - UbuntuCiro Santilli Путлер Капут 六四事View Answer on Stackoverflow
Solution 2 - UbuntuVonCView Answer on Stackoverflow
Solution 3 - UbuntuJürgen WeigertView Answer on Stackoverflow