71

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shan Khan
  • 9,667
  • 17
  • 61
  • 111
  • What's the use-case for needing the Ubuntu GUI from a docker container? Docker generally runs headless, so you could install X and run a VNC server or something I guess... but seems odd. – Jonnix Nov 17 '16 at 14:58
  • 4
    Docker images are supposed to run one app most typically a server or a compute app. Sometimes it gets to more that one app but usually not to serve the UI. UI needs lot more for which docker is not a good use case. – randominstanceOfLivingThing Nov 17 '16 at 15:00
  • i actually want to code python and debug all the things in the image, what would be the way to do so inside ubuntu image ? – Shan Khan Nov 17 '16 at 15:01
  • 1
    `all the things`. Please be more specific. You want to debug your python code, or more? – Jonnix Nov 17 '16 at 15:02
  • i want to setup complete tools to develop in python, visual studio code editor, firefox, dropbox to manage that code and same basic apps – Shan Khan Nov 17 '16 at 15:04
  • 8
    Use a VM then. This doesn't sound like an appropriate use of docker _at all_. – Jonnix Nov 17 '16 at 15:10
  • Probably [duplicate of this question](https://stackoverflow.com/questions/16296753/can-you-run-gui-apps-in-a-docker-container). – Pablo Bianchi Dec 01 '17 at 02:32
  • Another related question: https://stackoverflow.com/questions/52766270/download-and-run-ubuntu-desktop-with-gnome-support-via-docker/59287775#59287775 – Stefan Apr 22 '20 at 06:12

4 Answers4

80

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)
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
9

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.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thanks for clearing me , i guess i have to code python in visual studio code in my VS Code in host workstation and use the images of ubuntu python libraries docker images , right ? and build using that – Shan Khan Nov 17 '16 at 15:19
  • 2
    @ShanKhan That is the idea, yes. You can mount local folders into containers with docker run -v with data volumes (https://docs.docker.com/engine/tutorials/dockervolumes/#/mount-a-host-directory-as-a-data-volume) – VonC Nov 17 '16 at 15:32
  • The last link is broken (404). – Peter Mortensen Jul 24 '18 at 09:57
5

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

See Stack Overflow question Can you run GUI applications in a Docker container?.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jürgen Weigert
  • 2,618
  • 1
  • 16
  • 13
1

I found a simple way to solve this.

A common problem is that the docker doesn't have permission to access the display, so run the command below on your computer.

$ xhost +

After that, you need to know the param of your display.

$ echo $DISPLAY

Now, open your docker as root.

$ docker container run --rm --net host -v /tmp/.X11-unix:/tmp/.X11-unix -it image_name:tag

Give the param of your display to the container.

$ export DISPLAY=:0

Now you can run your GUI application.