基于 Arch Linux 的远程桌面的 Dockerfile 设置

Dockerfile setup for an Arch Linux based remote desktop

提问人:JoW 提问时间:10/9/2023 更新时间:10/11/2023 访问量:73

问:

我正在努力使以下所需的设置正常工作:

  • 基于 Arch 的系统(轻量级),用于远程桌面
  • 使用 RDP,因此我几乎可以从任何 Windows 计算机登录
  • 任何窗口管理器(在这个阶段,只要它有效,我实际上不再关心了)。xfce4 是我探索得最广泛的,但实际上,这并不重要。
  • Dockerfile(或 YAML/docker-compose)

我失败的方式多得数不清。使用谷歌搜索、bing.chat 和 chatGPT 无济于事。到目前为止,我最好的结果是一个运行(“docker run -it ...”)的系统,允许使用指定用户通过 xrdp 登录 - 但随后无法加载桌面环境。(这包括首先弄清楚安装 xrdp 的热。

这里是:

# Use the official Arch Linux base image
FROM archlinux:latest

# Update the package repository and install necessary packages
RUN pacman -Syu --noconfirm && pacman -S --noconfirm \
    xorg-server \
    xorg-xinit \
    xterm \
    sed \
    sudo

# Get Requirements for building xrdp
RUN pacman -S --noconfirm git base-devel nasm check fuse libfdk-aac ffmpeg imlib2

# Now make temp user to install - root won't be allowed to 
RUN useradd -m -p $(echo "installnow" | openssl passwd -1 -stdin) installer

# Switch to installer and change into installers home directory
USER installer
WORKDIR /home/installer

# Get yay change into yay dir and make package
RUN git clone https://aur.archlinux.org/xrdp.git
WORKDIR xrdp
RUN makepkg 

# Switch back to root for installation
USER root
WORKDIR /home/installer/xrdp

# have to install built package using pacman - because installation will fail without privileges (duh)
RUN pacman -U --noconfirm *.tar.zst

# Make sure xrdp uses 0.0.0.0 instead of default 127.0.0.1
RUN sed -i 's/127.0.0.1/0.0.0.0/g' /etc/xrdp/xrdp.ini /etc/xrdp/sesman.ini

# Generate a random 16-character alphanumeric password for root
RUN root_password=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16) && \
    echo "root:${root_password}" | chpasswd

# Add a dedicated user and set a password
RUN useradd -m rduser
RUN echo "rduser:secret12345" | chpasswd
RUN usermod -aG wheel rduser

# Create an Xinitrc file for starting the Xorg session
RUN echo "exec startxfce4" > /home/rduser/.xinitrc

# Set permissions for the rduser user
RUN chown rduser:rduser /home/rduser/.xinitrc

# Expose the RDP port (3389)
EXPOSE 3389

# Start xRDP and Xorg when the container runs
CMD ["xrdp", "-n"]

有人知道如何让它工作吗?

我假设我的麻烦应该或多或少可以通过这个 Dockerfile 轻松重现,但以防万一。主机系统是一个 stratto VPS:

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04                                                           
Codename:       jammy

5.15.0-83-generic x86_64

最好的,JoW

Docker archLinux 远程桌面

评论

0赞 David Maze 10/9/2023
直到最后一个要点,您描述的设置听起来完全像虚拟机,我可能会使用该技术。Docker 容器是单个进程的包装器,让它模拟完整的桌面环境可能很棘手。
0赞 JoW 10/10/2023
嘿,大卫,谢谢你的建议!诚然,我完全忽略了使用 VM 的可能性——主要是因为我的用例或多或少是“一次性系统”之一,而且我的印象是,docker 容器应该比 VM 更轻量级。因此,我将尝试一下 VM。尽管如此:我基本上被“挠痒痒”了,有点一心想让它工作。

答:

0赞 JoW 10/11/2023 #1

在当前版本中找到了使用 arch 的替代方案:debian slim。

以下 Dockerfile 生成一个工作系统:

# Use the official Debian "bookworm-slim" base image
FROM debian:bookworm-slim

# Set environment variables to avoid interactive prompts during installation
ENV DEBIAN_FRONTEND=noninteractive

# Generate a random 16-character alphanumeric password for root
RUN echo root:$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16) | chpasswd

# Update the package repository and install necessary packages
RUN apt-get update && apt-get install -y \
    xrdp \
    mate-desktop-environment-core \
    falkon

# Add a dedicated user and set a password
RUN useradd -m user
RUN echo "user:userpassword" | chpasswd
RUN usermod -aG sudo user

# Configure xRDP to use MATE as the default session
RUN echo mate-session > /home/user/.xsession

# Set up permissions for the user
RUN chown user:user -R /home/user

# Expose the RDP port (3389)
EXPOSE 3389

# Start xRDP when the container runs
CMD service xrdp start && /bin/bash