mviereck / x11docker

Run GUI applications and desktops in docker and podman containers. Focus on security.
MIT License
5.62k stars 378 forks source link

Start a DE as a container from login manager? #175

Closed alxlg closed 5 years ago

alxlg commented 5 years ago

I would like to know if it would be possible to start a DE (in particular one with a Wayland compositor) from the graphical login manager and use it as primary DE without starting the one provided by the host.

Login managers look for .desktop files in /usr/share/{x;wayland-}sessions where the command to start the DE is specified. Would it be possible to use a x11docker command to start for example Sway so the user can choose "Sway" entry from session menu in the login manager and just use it with no other DE/WM/Wayland compositor provided by the host?

mviereck commented 5 years ago

Yes, that is possible. I recently published a wiki entry on this topic: https://github.com/mviereck/x11docker/wiki/Display-manager-entry-for-x11docker

However, you still need Xorg or a Wayland compositor that will run on host. x11docker does not provide a setup where X or Wayland run in a container only without a "partner" on host that does the basic hardware access to monitor, GPU, keyboard, mouse etc.

For example, you can run Wayland compositor Sway provided in image x11docker/sway. But it will run nested in an X server or Wayland compositor from host. E.g. x11docker --gpu --xorg -- x11docker/sway will run Xorg on host and Sway in container. Sway will run nested in the Xorg session.

alxlg commented 5 years ago

@mviereck

Thank you for your reply, I think in future Linux desktop distro should somehow ship DEs in containers. The idea is described here: https://discussion.fedoraproject.org/t/is-it-possible-to-ship-a-de-with-containers/

Do you see any major downside of this approach? Also, did you think about using Podman instead of Docker to manage containers since it doesn't require to run as root nor a daemon running?

mviereck commented 5 years ago

Do you see any major downside of this approach?

It depends. The question is: What is the desire? Is there any advantage? x11docker already allows to run DEs like Xfce or LXDE in a container.

This works well with Xorg on host and an X DE in container. This way it is possible to have a small host system without mixing it with the bunch of DE dependencies. A useful example is x11docker/lxde-wine that contains all wine dependencies including multiarch packages that would otherwise flood my host system.

You can have an Xfce container and an LXDE container. You can share the same host home folder to have all personal files available. You can avoid to mix the DE specific applications. One DE provides pcmanfm, the other one thunar. You would not have two file managers side by side.

Wayland mixes the server/compositor and the DE. It is not possible to run a Wayland compositor in a container without giving it either quite privileged host access or running it nested in another X or Wayland compositor. E.g. you cannot split Sway into compositor and i3.

Also, did you think about using Podman instead of Docker to manage containers since it doesn't require to run as root nor a daemon running?

I'd like to test podman. Hopefully there will be a debian package soon: https://github.com/containers/libpod/issues/1742

alxlg commented 5 years ago

@mviereck

The point is being able as a normal user (without root permissions) to install a DE (download an image) and run it from the login manager (start the container from that image).

This would let us have a minimal (and maybe immutable) OS to run the software of choice of each user, including the DE.

The idea is mounting in each DE-container the folders with user's apps like Flatpak and AppImage ones so only those apps will be in common between the DE. This should fix annoying things like GNOME's Tracker from running in Plasma session for example, no?

The user's documents could be in a folder that is mounted in each container (not the whole /home/user folder to keep config separated, so one could run different version of the same DE without mixing the configurations).

In the end the login manager would present different sessions for each user, looking for sessions in a user's folder too and not only in system's /usr/share/xsessions and /usr/share/wayland-sessions.

I hope now it's more clear what I mean: if a user with no root permissions don't want to stay with default DE he should be able to install another one and have it has an entry in login manager's session menu. With containers it should be possible to do this without affecting the security of the system and the other users.

mviereck commented 5 years ago

The point is being able as a normal user (without root permissions) to install a DE (download an image) and run it from the login manager (start the container from that image).

I've just read your thread on fedora. You have a hard time to explain your point. :-)

Docker needs root permissions or membership in root-equivalent group docker. If podman really works well without this, it would be great.

A login manager could be forked to allow custom user sessions, maybe a simple one like https://github.com/evertiro/cdm. Meanwhile a workaround could be a softlink from a .desktop file in ~/usr/share/wayland-sessions to the user's home directory that can be edited by the user.

Let's say the root permissions issue would be solved with podman, and there is also a solution for a user-defined display manager entry.

Some possible issues that come to mind:

The user's documents could be in a folder that is mounted in each container (not the whole /home/user folder to keep config separated, so one could run different version of the same DE without mixing the configurations).

Some configuration might be desired in each DE. Bookmarks of browsers come to mind, or emails.

Edit: I think it is possible to find solutions for each issue. Maybe a shared host DBus already solves some issues. It could be allowed to add installation instructions to Dockerfiles to customize the images (instead of using a regular package manager). A flatpack folder on host could be shared across all DE containers. The host could automount in /media and /media ist shared with the DE. And so on. However, is it worth the effort? How often does one change his preferred DE?

alxlg commented 5 years ago

@mviereck

Thank you very much for all the informations, this is exactly what I was looking for!

However, is it worth the effort? How often does one change his preferred DE?

There are different use cases:

Meanwhile a workaround could be a softlink from a .desktop file in ~/usr/share/wayland-sessions to the user's home directory that can be edited by the user.

Yeah I thought the same for testing purpose while there is only one user. The final intent is having the login manager to display different session entries for each user :)

mviereck commented 5 years ago

Glad I could help. :-)

If you develop on this setup and have further questions or stumble over issues, feel free to ask further questions. I've already set up some desktop images, they might be useful for you: https://github.com/mviereck/x11docker#examples

Closing for now due to inactivity.

alxlg commented 5 years ago

@mviereck thank you very much!

mviereck commented 5 years ago

I want to tell that finally Gnome 3 runs in a container: x11docker/gnome.

It still has some issues. Many extensions do not work properly.