When I run "docker run" with a large docker image with docker run --privileged, Ubuntu virtual screen changes. How to keep it unchanged?

When I run “docker run” with a large docker image with docker run --privileged,
Ubuntu virtual screen changes. How to keep it unchanged?

Of course, pressing Ctrl+alt+f1~f7 restores the screen.

I don’t want to press ctrl+alt+f1~f7 key, is there any method?

Environment : Ubuntu 22.04
Docker Engine : 24.0.7
Docker Image : Ubuntu 20.04 + ROS2 + Realsense SDK (about 14GB)

Thank you very much.

Can you share your full command?

The short answer to the “How to keep it unchanged” question is “Don’t run the container in privileged mode” :slight_smile:

Of course this short answer will not help you. But I feel I have an idea only because I had a similar issue before, and I believe I know what you mean by “virtual screen”.

First of all, the privileged mode allows the container to do basically anything on the host. If you run systemd in a privileged container without proper configuration to optimize it for Docker, your GUI can restart.

Without knowing what your container does (because I don’t know much about ROS), it remains a guess, but if running the container affects the desktop environment on the host, the application might not suitable to run in a container. If it is, you need to find a configuration for the app that works. For example, systemd can run in containers, although it is different on each Linux distribution but one common requirement is to set the “ENV container=docker” environment variable.

The official ubuntu image doesn’t have systemd so if you ran it somehow, it was installed as a dependency due to a wrong attempt to install ROS2 and the SDK.

Have you read this documentation from ROS?

https://docs.ros.org/en/foxy/How-To-Guides/Run-2-nodes-in-single-or-separate-docker-containers.html

Thanks for your comment.
This is a full command
$docker run -it -d --privileged -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:ro --name docker-20.04 -p 3579:22 -h docker-ubuntu -u root ubuntu:20.04-base-v1.1 /sbin/init

Thanks for reply, Takacs,

You are right. systemd restart ubunut GUI.
This is full command
$docker run -it -d --privileged -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:ro --name docker-20.04 -p 3579:22 -h docker-ubuntu -u root ubuntu:20.04-base-v1.1 /sbin/init

I change like this
docker run -it -d --privileged -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:ro --name docker-20.04 -p 3579:22 -h docker-ubuntu -u root ubuntu:20.04-base-v1.1 /usr/bin/bash

and then, virtual console is not changed…

Is there any method to use “systemd” without changing vitual console?

Thank you very much.

I don’t recommend using systemd in a Docker container. When you try that, it usually means you don’t follow the recommended installation process of an application to run in a container. I have to quote my previous question which you forgot to reply:

If you want to read what I learned about systemd and Docker two years ago, you can find it here:

https://github.com/rimelek/tutorial-linux-signals/tree/48ac221303c48dc5b03197d4b1e65fd00fc1dffa?tab=readme-ov-file#systemd

I recommend reading the whole readme and checking the source code to see why we don’t use systemd in a container usually.

Yes, I read the ROS documentation. Foxy is old, Iron is updated. ^^

I use the ROS2 and camera, but this camera need privileged mode.
sometime, I want to use systemctl command, so I want to use privileged mode.

Thank you very much…