Score:1

Wine in Docker - "reg add" only keeps effects temporarily

cn flag

Ive been bashing my head against a wall about this.

I'm looking to add an executable to the PATH under wine on Ubuntu 20.04. Trying to configure this from the dockerfile, but having a weird issue. Specifically, i'm trying to install python under wine such that you can call wine python. I have opted to try using embedded python and manually installing pip through get_pip.py (Not shown here).

In the Dockerfile, I have:

FROM ubuntu:20.04

RUN useradd --no-log-init -r --uid 1003 -G dialout -g 100 -s /bin/bash jenkins

# PULL /wine/winecfg from private server pre-configured

RUN dpkg --add-architecture i386 \
    && apt get update
    && apt get install -y \
    libc6:i386 \
    && apt get install -y \
    wine=5.0-3

RUN mkdir -p /wine/winecfg && chown -R jenkins:users /wine

# Add Embedded Python
ARG Python_Embedded_Archive=python-3.9.7-embed-win32.zip
RUN apt-get install -y unzip
COPY ${Python_Embedded_Archive} /temp/${Python_Embedded_Archive}
RUN unzip /temp/${Python_Embedded_Archive} -d /wine/python
RUN chmod +x /wine/python/python.exe
RUN chown jenkins:users /wine/python

# Switch to jenkins, which owns wine
USER jenkins:true

# Add Embedded Python to PATH in wine
COPY add_to_wine_path.sh /wine
RUN bash /wine/add_to_wine_path.sh /wine/python \
    && wine python --version
RUN wine python --version

Note: This not the full dockerfile, just the relevant parts

The /wine/cfg folder is f

With add_to_wine_path.sh:

path_to_add=$1
echo "Adding '$path_to_add' to Wine's PATH variable"

# Get clean the current path values (generally empty, but script could be called a second time)
existing_path=$(wine reg QUERY 'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -v PATH | grep -Po '(?<=\^%).*(?=\^%)')

# If the existing path value is empty
if [ -z $existing_path" ]
then
    # Set the default path values (Windows paths)
    existing_path="C:\windows\system32;C:\windows"
fi

wine reg add 'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -v PATH /t REG_EXPAND_SZ /d ^%\;&path_to_add\;$existing_path^% /f

What actually happens:
When I build the docker image, the first call to wine python --version works, indicating that the PATH was updated. YAY!
But, when the second wine python --version runs in a different RUN block, it fails.

This seems to me like the registry needs to be forced to update for all users in wine, effectively a reboot.

So I tried wineboot with all the various options and that still didn't help.

Any Windows Registry or Wine gurus know whats going on here?

Score:1
cn flag

I've been trying to persist a wine registry change in Docker too, and I found through experimentation that in my environment it takes between 1 and 2 seconds for the registry file (~/.wine/user.reg) to be modified after invoking wine reg add.

There is a related query here. Hopefully there is a way to synchronously flush the registry to disk; otherwise the easiest thing might be to loop until the file is modified.

Here is how I did it in one situation (this registry change enables the "Show dot files" option):

RUN before=$(stat -c '%Y' /home/xclient/.wine/user.reg) \
    && wine reg add 'HKEY_CURRENT_USER\Software\Wine' /v ShowDotFiles /d Y \
    && while [ $(stat -c '%Y' /home/xclient/.wine/user.reg) = $before ]; do sleep 1; done

This is probably safe because it's a single change to the default registry (which is not very large: only 16KB apparently), but all sorts of things could go wrong in more complex situations:

  • If you make multiple modifications to the registry, they may not all be flushed to disk at the same time, so looking at the file modification date would be insufficient
  • It might be possible to exit the loop while the file is still being written to disk, so you would end up with a corrupt registry file
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.