As an evolution on can you run GUI apps in a docker container, is it possible to run GUI applications via Docker without other tools like VNC or X11/XQuartz?
In VirtualBox, you could pass the --type gui to launch a headed VM, and this doesn't require installing any additional software. Is anything like that possible via Dockerfile or CLI arguments?
Docker doesn't provide a virtual video device and a place to render that video content in a window like a VM does.
It might be possible to run a container with --privileged and write to the Docker hosts video devices. That would possibly require a second video card that's not in use. The software that Docker runs in the container would also need to support that video device and be able write directly to it or a frame buffer. This limits what could run in the container to something like an X server or Wayland that draws a display to a device.
You could try the following which is worked in my case.
Check the Local machine display and its authentication
[root#localhost ~]# echo $DISPLAY
[root#localhost ~]# xauth list $DISPLAY
localhost:15 MIT-MAGIC-COOKIE-1 cc2764a7313f243a95c22fe21f67d7b1
Copy the above authentication and join your existing container, and add the display autherntication.
[root#apollo-server ~]# docker exec -it -e DISPLAY=$DISPLAY 3a19ab367e79 bash
root#3a19ab367e79:/# xauth add 192.168.10.10:15.0 MIT-MAGIC-COOKIE-1 cc2764a7313f243a95c22fe21f67d7b1
root#3a19ab367e79:/# firefox
Related
I have two machines,
machine A: system ubuntu 20.04 (DISPLAY :0)
machine B: system windows 10
in machine A, I create a docker container with the following command:
docker run --rm -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY -v $(pwd):/home/walid/notebooks opencv bash
the docker container has Visual Studio Code installed and OpenCV, I run the following command to go in the container bash:
docker exec -it $containerId bash
inside the container, I go into the folder notebooks and run the following commands:
code . # to launch the visual studio code
result; the visual studio code opens
python read.py # to open a video capture with OpenCV
result; good the video capture opens
now int the machine B; I use the Remote Desktop Connection to machine B, when I go inside the container to open Visual Studio Code nothings happing doesn't open, when I try python read.py I get an error could not connect to display :10.0
I figure out where I was doing it wrong:
(base) adminsst#admins:~$ xhost
access control enabled, only authorized clients can connect
SI:localuser:adminsst
(base) adminsst#admins:~$ sudo su
root#admins:/home/adminsst# xhost
No protocol specified
xhost: unable to open display ":10.0"
whene I was runing the container in the sudo su it doesn't work, but when I sudo docker run .... it works.
but now when I login to another user in the server (machine A) and do the same think it doesn't work anymore and I will get the same error could not connect to display :11.0
SOLUTION 1
here's the solution I did and it works for me:
first if you run the following command in the new user you will get:
walid#admins:~$ xhost
access control enabled, only authorized clients can connect
now run the this one again to have this result:
walid#admins:~$ xhost +local:
non-network local connections being added to access control list
to launch the GUI app you need to pass the new DISPLAY to the container because it will had been changed every time you login to solve this problem just run the following command:
walid#admins:~$ sudo docker exec -it -e DISPLAY=$DISPLAY open bash
that's all now you will be able to launch the GUI app without any problem, but still every time you login you should exect the following command xhost +local: before starting the container, if someone has a solution for that please let me know
SOLUTION 2
see the following url here
xhost +local:`docker inspect --format='{{ .Config.Hostname }}' $containerId`
docker start $containerId
there more useful solutions
--------
Another thing I have faced, that even when I do the above steps, sometimes doesn't work, I simply change the display ID in the docker container to the same as Local machine ID by the following;
first figure out the local machine display ID by
echo $DISPLAY
then in the docker container do the following
$DISPLAY=:ID
On a mac, docker utilizes HyperKit in order to create a LinuxKit VM. This means, for example, among other things, that I cannot see any of the image layers that are pulled down for a given container in places like /var/lib/docker, since the VM controls all of that.
Is there a way to actually get a shell on that VM to be able to do that sort of introspection?
In Docker Desktop 2.4 for Mac, it is possible to get a nearly full terminal into the LinuxKit VM, with sane tab auto-completion, and be able to inspect its contents.
For example, to see the layers of pulled down docker images, you may perform the following commands:
$ stty -echo -icanon && nc -U ~/Library/Containers/com.docker.docker/Data/debug-shell.sock && stty sane
/ # ls -al /var/lib/docker/overlay2/
The nc -U ~/Library/Containers/com.docker.docker/Data/debug-shell.sock may be run on its own, per the Docker release docs, but if it is not combined with stty per the above example, you will not see very good output, nor will you have tab completion in the vm.
Is there any way that the docker environment could be given to multiple USB devices, say /dev/video0, /dev/video4 and /dev/ttyUSB4?
In case of a single device, it could be
docker run -t -i --device=/dev/ttyUSB4 ubuntu bash
and for multiple devices
docker run -t -i --privileged -v /dev/bus/usb:/dev/bus/usb ubuntu bash
But I needed to know if there is anyway I could provide access like in the former case to specific devices alone (Not using privilages mode).
Docker works with device option as an array. So,
you can specify several devices also with device option:
docker run -ti --device=/dev/ttyUSB4 --device=/dev/video0 --device=/dev/video4 ubuntu bash
In docker-compose is also possible:
docker-compose.yml
...
services:
myservice:
...
devices:
- "/dev/ttyUSB4:/dev/ttyUSB4"
- "/dev/video0:/dev/video0"
- "/dev/video4:/dev/video4"
There's another possibility giving linux capability, but it's unrecommended (dangerous like privileged mode) for production: FOWNER capability:
docker run -ti --cap-add=FOWNER ubuntu bash
Nevertheless, in kubernetes, for example, it's not enough and you need privileged mode.
Not 100% sure this is the right place but let's try.
I'm using on my Windows laptop the Docker Quickstart Terminal (docker toolbox) to get access to a Linux env with Google AppEngine, python, mysql...
Well, that seems to work and when I type docker run -i -t appengine /bin/bash I get access to this env.
Now I'd like to have access to some of my local (host) files so I can edit them with my Windows editors but run them into the docker instance.
I've seen a -v option but cannot make it work.
What I do
docker run -v /d/workspace:/home/root/workspace:rw -i -t appengine /bin/bash
But workspace stays empty in the Docker instance...
Any help appreciated
(I've read this before to post: https://github.com/rocker-org/rocker/wiki/Sharing-files-with-host-machine#windows)
You have to enable Shared Drives , you can follow this Blog
I'm running a docker toolbox installed on my Windows 7 computer, I'm trying to access the docker from outside (win desktop) so I can get a GUI App working (let say we will test with Firefox)
As you all know, docker does not come with Server X, so I've found the solution is to install xcygwin to perform X11 tasks and then run the container via ssh so it could be displayed on my Windows.
The problem is I cant set the display right, I do:
export DISPLAY=:0.0
And tried few other options like exporting to the IP of the host, exporting to localhost etc.. then I SSH into my docker by running:
docker-machine ssh default -X
(the -X supposed to activate the x11 forwarding if I'm not wrong)
Now, I get into my docker, so simply I try to run my magic firefox container by running something like this:
docker run --rm -e DISPLAY=$DISPLAY devurandom/firefox
I get the expected Error: cannot open display.
Right! I didnt set the display in my docker! so I did :
DOCKER=0.0
I get Cannot open display: 0.0!
I also tried this one which I couldnt figure where the Path is comming from but well..
docker run -ti -v /tmp/serverX:/tmp/ServerX -e DISPLAY=$DISPLAY ...
No luck, does anyone know how to fix this?