- About docker-wine
- Running from Docker Hub image
- Build and run locally on your PC
- Running the docker-wine script
- Volume container winehome
- ENTRYPOINT script explained
- Using docker-wine in your own Dockerfile
The docker-wine
image was created so I could experiment with Wine while learning the ropes for using Docker containers. The image is based on Ubuntu 18.04 and includes Wine version 4.0 (stable branch) and the latest version of Winetricks to help manage your Wine bottles.
Included below are instructions for running the docker-wine
container that allows you to use the Docker host's X11 session to display graphics and its PulseAudio server for sound through the use of UNIX sockets.
The source code is freely available from the scottyhardy/docker-wine GitHub repository for you to build the image yourself and contributions are welcome.
Create a volume container so user data is kept separate and can persist after the docker-wine
container is removed:
docker volume create winehome
Please note: It is not recommended to use your own home folder for storing data as it will change ownership to wineuser
, which has a UID and GID of 1010
.
The recommended commands for running docker-wine
are:
docker run -it \
--rm \
--env="DISPLAY" \
--volume="${XAUTHORITY}:/root/.Xauthority:ro" \
--volume="winehome:/home/wineuser" \
--net="host" \
--name="wine" \
scottyhardy/docker-wine <Additional arguments e.g. wine notepad.exe>
This assumes the $XAUTHORITY
environment variable is set to the location of the MIT magic cookie. If not set, the default location is in the user's home so you can replace ${XAUTHORITY}
with ${HOME}/.Xauthority
. This file is required to allow the container to write to the current user's X session. For this to work you also need to include the --net=host
argument when executing docker run
to use the host's network stack which includes the X11 socket.
As a one-off, you will need to create the file .config/pulse/default.pa
in your home folder, to enable you to create a shared UNIX socket /tmp/pulse-socket
to allow other users on the same host to access the user's PulseAudio server:
mkdir -p "${HOME}/.config/pulse"
echo -e ".include /etc/pulse/default.pa\nload-module module-native-protocol-unix auth-anonymous=1 socket=/tmp/pulse-socket" > ${HOME}/.config/pulse/default.pa
Restart your PulseAudio server to create the new socket:
pulseaudio -k
pulseaudio --start
Now you're ready to run the container using PulseAudio for sound:
docker run -it \
--rm \
--env="DISPLAY" \
--volume="${XAUTHORITY}:/root/.Xauthority:ro" \
--volume="/tmp/pulse-socket:/tmp/pulse-socket" \
--volume="winehome:/home/wineuser" \
--net="host" \
--name="wine" \
scottyhardy/docker-wine <Additional arguments e.g. winetricks vlc>
First, clone the repository from GitHub:
git clone https://github.com/scottyhardy/docker-wine.git
To build the container, simply run:
make
To run the container and start an interactive session with /bin/bash
run either:
make run
or use the docker-wine
script as described below.
When the container is run with the docker-wine
script, you can override the default interactive bash session by adding wine
, winetricks
, winecfg
or any other valid commands with their associated arguments:
./docker-wine wine notepad.exe
./docker-wine winecfg
./docker-wine winetricks msxml3 dotnet40 win7
When the docker-wine image is instantiated with ./docker-wine
script or with the recommended docker volume create
and docker run
commands, the contents of the /home/wineuser
folder is copied to the winehome
volume container on instantiation of the wine
container.
Using a volume container allows the wine
container to remain unchanged and safely removed after every execution with docker run --rm ...
. Any user environments created with docker-wine
will be stored separately and user data will persist as long as the winehome
volume is not removed. This effectively allows the docker-wine
image to be swapped out for a newer version at anytime.
You can manually create the winehome
volume container by running:
docker volume create winehome
If you don't want the volume container to persist after running ./docker-wine
, just add --rm
as your first argument.
e.g.
./docker-wine --rm wine notepad.exe
Alternatively you can manually delete the volume container by using:
docker volume rm winehome
The ENTRYPOINT
set for the docker-wine image is simply /usr/bin/entrypoint
. This script is key to ensuring the user's .Xauthority
file is copied from /root/.Xauthority
to /home/wineuser/.Xauthority
and ownership of the file is set to wineuser
each time the container is instantiated.
Arguments specified after ./docker-wine
or after the docker run ... docker-wine
command are also passed to this script to ensure it is executed as wineuser
.
For example:
./docker-wine wine notepad.exe
The arguments wine notepad.exe
are interpreted by the wine
container to override the CMD
directive, which otherwise simply runs /bin/bash
to give you an interactive bash session as wineuser
within the container.
If you plan to use scottyhardy/docker-wine
as a base for another Docker image, you should set up the same entrypoint to ensure you run as wineuser
and X11 graphics continue to function by adding the following to your Dockerfile
:
FROM scottyhardy/docker-wine:latest
... <your code here>
ENTRYPOINT ["/usr/bin/entrypoint"]
Or if you prefer to run a program by default you could use:
ENTRYPOINT ["/usr/bin/entrypoint", "wine", "notepad.exe"]
Or if you want to be able to run a program by default but still be able to override it easily you could use:
ENTRYPOINT ["/usr/bin/entrypoint"]
CMD ["wine", "notepad.exe"]