After upgrading to Debian Jessie, my Windows application running under Wine stopped working. In this article we’ll use Docker to restore the Wine environment from Debian Wheezy. We’ll run the Windows application inside this Docker container.
Docker is not part of the stable Jessie distribution, however, you can install it from the Debian Backports repositories.
Creating a Docker image
We start off with creating a Docker image based on the debian:wheezy
image from the official Docker repositories. We’ll install the 32-bit Wine package on it. The Wine application is a graphical application and hence requires access to the X server. Setting the environmet variable DISPLAY=:0
instructs the application to access the local X server. The complete Dockerfile
to build our Wine image looks as follows:
|
|
You can kick off the build of the wine1.4
image with:
|
|
After a minute or two the build is complete and the resulting image is stored locally on your Docker host. You can take a look using the docker images
command:
|
|
Running Wine within a Docker container
To test our wine1.4
Docker image, we’ll run the notepad
application which comes with Wine:
|
|
The notepad
application doesn’t really start. From the generated error output we can see that our application is unable to access the X server. Well, there’s no X server running inside the container. In order to allow the application running inside the container to access the X server running on the Docker host, we’ll expose the host’s X server UNIX domain socket inside the container. We can ask Docker to bind mount the /tmp/.X11-unix/X0
UNIX socket to the same location inside the container using the --volume
parameter:
|
|
When we run the above command, Wine starts up successfully and the notepad application opens up. Inside the Docker container Wine runs as user root and starts from scratch with no existing configuration:
We would like Wine running inside the Docker container to use the existing Wine configuration stored on the Docker host. Let’s copy the existing Wine configuration on the host to a new directory which we’ll in turn expose inside the Docker container:
|
|
The .wine.docker
directory can be exposed inside the Docker container with the command-line parameter --volume /home/anosek/.wine.docker:/home/anosek/.wine
. The Wine configuration in .wine.docker
is in my case owned by the user anosek
. We want Docker to run as user anosek
instead of the default root
user. In order to accomplish this, two additional parameters to the Docker run
command are needed: --volume /etc/passwd:/etc/passwd
and --user anosek
. We’re bind mounting the /etc/passwd
file including the definition of user anosek
inside the Docker container and asking Docker to run as user anosek
.
The complete command to run Wine inside the Docker container as user anosek
and using the existing Wine configuration found in the /home/anosek/.wine.docker
directory on the host looks as follows:
|
|
Conclusion
One can leverage the modern Docker technology to create a specific Wine environment on any Linux system. To achieve this a little bit of configuration is required, though. In case of Wine you might be better off using some of the specialized tools for Wine management. For instance,
PlayOnLinux can manage different versions of Wine as well as different prefixes (WINEPREFIX
environment variable).