LoginSignup
35
43

More than 5 years have passed since last update.

DockerからGUIアプリとWineアプリを使う方法

Last updated at Posted at 2016-01-27

DockerからGUIアプリを使う方法にはいくつかの方法があります。一つは、VNC経由で、もう一つはSSH経由です。

LinuxでWindowsアプリを動かしたいことがあります。私は、そんな時、Wineで動かして、VNCやSSHで接続するのですが(ほとんど外部サーバーで動かしてるので)、Docker Imageも使います。

ホストはArch Linuxでいきます。ゲストはUbuntuを使います。

Dockerで起動したGUIアプリに接続するまで

Host,ArchLinux
$ sudo pacman -S docker lxc openssh

$ docker -v

$ sudo cp /usr/lib/systemd/system/docker.service /etc/systemd/system/docker.service

$ sudo mkdir -p /etc/systemd/system/docker.service.d/

$ sudo vim /etc/systemd/system/docker.service.d/lxc.conf
[Service]
ExecStart=
ExecStart=/usr/bin/docker -d -e lxc

$ sudo vim /etc/ssh/sshd_config
AllowAgentForwarding yes
AllowTcpForwarding yes
GatewayPorts no
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes

$ sudo systemctl start docker
$ sudo systemctl start sshd

Dockerfileを書いてきます。

~/docker/firefox/Dockerfile
FROM ubuntu:14.04

RUN apt-get update && apt-get install -y firefox

# Replace 1000 with your user / group id
RUN export uid=1000 gid=1000 && \
    mkdir -p /home/developer && \
    echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd && \
    echo "developer:x:${uid}:" >> /etc/group && \
    echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && \
    chmod 0440 /etc/sudoers.d/developer && \
    chown ${uid}:${gid} -R /home/developer

USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox

参考:http://postd.cc/running-gui-apps-with-docker

起動方法はこんな感じのオプションを使います。

$ cd ~/docker/firefox

$ sudo docker build -t firefox .

# Guest:Ubuntu
$ sudo docker run -ti --rm \
  -e DISPLAY=$DISPLAY \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  firefox

developer@docker $ firefox

次に、Wine用のコンテナを作ってみます。

~/docker/wine/Dockerfile
FROM ubuntu:14.04

RUN dpkg --add-architecture i386
RUN apt-get update -y
RUN apt-get install --no-install-recommends software-properties-common -y
RUN add-apt-repository -y ppa:ubuntu-wine/ppa
RUN apt-get update -y
RUN apt-get install wine1.7 winetricks winbind -y

RUN cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
RUN apt-get install language-pack-ja -y && update-locale LANG=ja_JP.UTF-8
RUN apt-get install fonts-takao fonts-takao-gothic fonts-takao-pgothic fonts-takao-mincho
RUN sed -i -e 's/^XKBMODEL="pc105"/XKBMODEL="jp106"/g' /etc/default/keyboard
RUN sed -i -e 's/^XKBLAYOUT="us"/XKBLAYOUT="jp"/g' /etc/default/keyboard
RUN apt-get purge software-properties-common -y
RUN apt-get autoclean -y
RUN export uid=1000 gid=1000 && \
    mkdir -p /home/wineuser && \
    echo "wineuser:x:${uid}:${gid}:Developer,,,:/home/wineuser:/bin/bash" >> /etc/passwd && \
    echo "wineuser:x:${uid}:" >> /etc/group && \
    echo "wineuser ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/wineuser && \
    chmod 0440 /etc/sudoers.d/wineuser && \
    chown ${uid}:${gid} -R /home/wineuser

USER wineuser
ENV HOME /home/wineuser
ENV LANG ja_JP.UTF-8
WORKDIR /home/wineuser
CMD /bin/bash

後は、先ほどと同じようにDocker Build, Runします。

$ cd ~/docker/wine

$ sudo docker build -t wine:base .

# `lxc.network.hwaddr = ac:ac:ac:11:22:33`では、アプリによってハード固有の番号が読み込まれることがあるので便宜上指定します。
$ sudo docker run -ti --rm --lxc-conf="lxc.network.hwaddr = ac:ac:ac:11:22:33" \
  -e XMODIFIERS="@im=fcitx" \
  -e GTK_IM_MODULE=fcitx \
  -e QT_IM_MODULE=fcitx \
  -e XIMPROGRAM=fcitx \
  -e LC_CTYPE=ja_JP.UTF-8 \
  -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix \
  wine:base

wineuser@docker $ wget http://cdn.line-apps.com/client/win/new/LineInst.exe
wineuser@docker $ wine LineInst.exe
--------------------------------------------
$ sudo docker ps
commitID

$ sudo docker commit ${commitID} wine:line
$ sudo docker images
wine line
wine base

$  sudo docker run -ti --rm --lxc-conf="lxc.network.hwaddr = ac:ac:ac:11:22:33" \
  -e XMODIFIERS="@im=fcitx" \
  -e GTK_IM_MODULE=fcitx \
  -e QT_IM_MODULE=fcitx \
  -e XIMPROGRAM=fcitx \
  -e LC_CTYPE=ja_JP.UTF-8 \
  -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix \
  wine:line

参考:http://netbuffalo.doorblog.jp/archives/5001669.html

35
43
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
35
43