Wine In Docker

Introduction

Wine is a common tool to run Windows applications on Linux. In this blog post, I would like to discuss how to run Windows applications, such as WeChat, via Wine in a Linux Docker container.

Docker Wine

We will quickly go through the Wine Dockerfile and the basic Wine usages. All the commands could also be translated to a native Ubuntu operating system.

Dockerfile

The following Dockerfile has the Wine, languages, Chinese fonts, and display scaling installed.

wine.Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
software-properties-common \
ca-certificates \
language-pack-en \
language-pack-zh-han* \
locales \
locales-all \
wget

# Install Wine
RUN dpkg --add-architecture i386 && \
mkdir -pm755 /etc/apt/keyrings && \
wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key && \
wget -nc -P /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/$(lsb_release -sc)/winehq-$(lsb_release -sc).sources && \
apt-get update -y && \
# Wine 7.0 stable has some issues with some games I tested
# Use Wine 7.11 staging instead
apt-get install -y --install-recommends winehq-staging

# GStreamer plugins
RUN apt-get update -y && \
apt-get install -y --install-recommends \
gstreamer1.0-libav:i386 \
gstreamer1.0-plugins-bad:i386 \
gstreamer1.0-plugins-base:i386 \
gstreamer1.0-plugins-good:i386 \
gstreamer1.0-plugins-ugly:i386 \
gstreamer1.0-pulseaudio:i386

# Install dependencies for display scaling
RUN apt-get update -y && \
apt-get install -y --install-recommends \
build-essential \
bc \
git \
xpra \
xvfb \
python3 \
python3-pip

# Install OpenGL acceleration for display scaling
RUN pip3 install PyOpenGL==3.1.5 PyOpenGL_accelerate==3.1.5

# Install display scaling script
RUN cd /tmp && \
git clone https://github.com/kaueraal/run_scaled.git && \
cp /tmp/run_scaled/run_scaled /usr/local/bin/

# Install missing fonts for Chinese
RUN apt-get update -y && \
apt-get install -y --install-recommends \
fonts-wqy-microhei

# Install driver for Intel HD graphics
RUN apt-get -y install libgl1-mesa-glx libgl1-mesa-dri

ENV LC_ALL zh_CN.UTF-8
ENV LANG zh_CN.UTF-8
# Make sure the terminal is still English
ENV LANGUAGE en_US.UTF-8

Build Docker Image

To build the Docker image, please run the following command.

1
$ docker build -f wine.Dockerfile --tag wine:20.04 .

Run Docker Container

To run the Docker container, please run the following command with additional Docker arguments if necessary.

1
2
3
4
5
6
7
8
9
10
11
12
$ xhost +
$ docker run \
-it \
--rm \
--device /dev/snd \
--device /dev/dri \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix:ro \
-v $(pwd):/mnt \
-w /mnt \
wine:20.04
$ xhost -

Configure Wine

For Win32 applications, we create a directory ~/.wine32 to store the configurations.

1
$ WINEARCH=win32 WINEPREFIX=~/.wine32 winecfg

For Win64 applications, we create a directory ~/.wine64 to store the configurations.

1
$ WINEARCH=win64 WINEPREFIX=~/.wine64 winecfg

Run Application

For Win32 applications, we specify the Win32 configuration directory as WINEPREFIX before wine.

1
$ WINEPREFIX=~/.wine32 wine app.exe

For Win64 applications, we specify the Win64 configuration directory as WINEPREFIX before wine.

1
$ WINEPREFIX=~/.wine64 wine app.exe

Run Display Scaling

For some old applications, the display usually is very small. We could scale the display using a scaling script.

For example, to scale the display of app.exe by 1.5x, we could run the following command.

1
$ WINEPREFIX=~/.wine32 run_scaled --scale=1.5 wine app.exe

Save Docker Image

We can save the Docker image from the Docker container we just set up using docker commit. In case we accidentally turn off the Docker container, we can always start the Docker container again from the Docker image without having to reinstall Wine and the application.

Example

We will use running Windows WeChat as an example.

Download WeChat

1
$ wget https://dldir1.qq.com/weixin/Windows/WeChatSetup.exe

Run Docker Container

1
2
3
4
5
6
7
8
9
10
11
12
13
$ xhost +
$ docker run \
-it \
--device /dev/snd \
--device /dev/dri \
-e DISPLAY=$DISPLAY \
-e XMODIFIERS=@im=fcitx \
-e QT_IM_MODULE=fcitx \
-e GTK_IM_MODULE=fcitx \
-v /tmp/.X11-unix:/tmp/.X11-unix:ro \
-v $(pwd):/mnt \
-w /mnt \
wine:20.04

Notice --rm has been removed and -e XMODIFIERS=@im=fcitx, -e QT_IM_MODULE=fcitx, -e GTK_IM_MODULE=fcitx has been added to enable the fcitx input from the host computer.

Configure Wine

1
$ WINEARCH=win64 WINEPREFIX=~/.wine64 winecfg

Make sure virtual desktop is used in winecfg. In my case, I used resolution 2560 x 1440 for the virtual desktop.

Install WeChat

1
2
$ cd /mnt
$ WINEPREFIX=~/.wine64 wine WeChatSetup.exe

WeChat will be installed in ~/.wine64/drive_c/Program\ Files\ \(x86\)/Tencent/WeChat/WeChat.exe by default.

Run WeChat

1
$ WINEPREFIX=~/.wine64 wine ~/.wine64/drive_c/Program\ Files\ \(x86\)/Tencent/WeChat/WeChat.exe

I tried fcitx input from the host computer to the WeChat in the container and it worked fine.

References

Author

Lei Mao

Posted on

07-11-2022

Updated on

09-19-2023

Licensed under


Comments