LoginSignup
5
7

More than 3 years have passed since last update.

Ubuntu の Desktop 環境を Docker で

Last updated at Posted at 2019-11-28

本日は

を参考に自分の環境でも再現したよ〜報告を書きます.Ubuntuさん基本的にターミナルベースでしか使わないので応用はとくに考えてないのですが・・・

環境

ホスト:macOS Catalina
Docker: Docker version 19.03.5, build 633a0ea

Dockerfile

FROM ubuntu:16.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
    ubuntu-desktop \
    samba-common-bin \
    x11-apps \
    sudo

ARG uid=1000
ARG gid=1000
RUN groupadd -g ${uid} developer && \
    useradd -u ${gid} -g developer -G sudo -r developer && \
    mkdir -p /home/developer/.config/nautilus &&\
    chown ${uid}:${gid} -R /home/developer && \
    mkdir -p /var/lib/samba/usershares

RUN echo 'Defaults visiblepw'             >> /etc/sudoers
RUN echo 'developer ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# set locale to initialize terminal property
RUN locale-gen en_US.UTF-8  
ENV LANG en_US.UTF-8  
ENV LANGUAGE en_US:en  
ENV LC_ALL en_US.UTF-8

USER developer
WORKDIR /home/developer

使い方

下記のようなシェルスクリプトを作っておきます.

init.sh
docker build -t udesk .
xhost + 127.0.0.1
HOSTDISPLAY=host.docker.internal:0
docker run --rm -it\
       -e DISPLAY=$HOSTDISPLAY \
       -v /tmp/.X11-unix/:/tmp/.X11-unix \
       --name udesk \
       udesk /bin/bash -c "nautilus"
xhost - 127.0.0.1

あとは bash init.sh でイメージのビルドから起動までできます.他のターミナルを開いておいて docker stop udesk で止めることができます.--rm オプションをつけてるので終わるとコンテナが消えてしまいます.ですので引き続き使いたい人は --rm を取り除いてコンテナを再起動する感じでお願いします.

  • 上の init.sh で書いている xhost +/ xhost - のテクニックはDocker のコンテナで matplotlib の描画結果を表示させたいな場合にも応用が効きますね.
  • Linux がホストの場合は xhost + local:docker/ xhost - local:docker とか HOSTDISPLAY=$DISPLAY としておくとうまくいくはずです.

References

References for those who would like to try with XForwarding

5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7