Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open Ubuntu GUI inside a Docker image

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?

like image 628
Shan Khan Avatar asked Nov 17 '16 14:11

Shan Khan


People also ask

Can you run Ubuntu GUI in Docker?

Many thanks to Docker! Using a Docker image, you can run Ubuntu with LXDE and LXQt desktop environments and access it via an HTML5 VNC interface.

Can I run GUI in Docker?

Follow the below steps to run a GUI application inside Docker: Step 1: Install and Start Docker and check the status and restart the service. The Systemctl commands are used to manage system services. systemctl start docker // to start the docker service.

How do I see inside a Docker image?

To analyze a Docker image, simply run dive command with Docker "Image ID". You can get your Docker images' IDs using "sudo docker images" command. Here, ea4c82dcd15a is Docker image id. The Dive command will quickly analyze the given Docker image and display its contents in the Terminal.


3 Answers

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:

  • visit: http://127.0.0.1:6080/#/ which runs a noVNC more limited JavaScript VNC client

  • run:

    sudo apt-get install tigervnc-viewer
    xtigervncviewer :5900
    

    To go into fullscreen mode, hit F8 and click on menu entry, or just F8 followed by T: https://superuser.com/questions/285843/how-do-i-switch-in-out-of-fullscreen-mode-from-the-command-line-in-realvnc You might need to close and reopen the screen after that for the image to get larger.

    I also tried vinagre, but it was much laggier when scrolling Firefox on YouTube.

    Inside vinagre, you might want to go into full screen mode to be able to see the full desktop

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:

  • How to play sound in a Docker container on Mac OS Yosemite
  • https://forums.docker.com/t/how-to-get-sound/36527
  • https://github.com/fcwu/docker-ubuntu-vnc-desktop/issues/49

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:

  • Can you run GUI applications in a Linux Docker container?

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)

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

like image 9
VonC Avatar answered Oct 23 '22 21:10

VonC


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

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

like image 5
Jürgen Weigert Avatar answered Oct 23 '22 21:10

Jürgen Weigert