简体   繁体   English

在 Docker(适用于 Windows)中 如何在构建映像时批量添加注册表项?

[英]In Docker (for Windows) How can I add registry entries in bulk while building my image?

I'm using Docker for Windows and building the docker image with a Dockerfile like this:我将 Docker 用于 Windows 并使用 Dockerfile 构建 docker 图像,如下所示:

FROM mydockerhublogin/win2k16-ruby:1.0

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app


# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME World

RUN powershell -Command \
    $ErrorActionPreference = 'Stop'; \
  New-Item "HKLM:\Software\WOW6432Node\ExampleCom" -Force ; \
  New-ItemProperty "HKLM:\Software\WOW6432Node\ExampleCom" -Name MenuLastUpdate -Value "test" -Force

RUN powershell -Command \
    $ErrorActionPreference = 'Stop'; \
  New-Item "HKLM:\Software\ExampleCom" -Force ; \
  New-ItemProperty "HKLM:\Software\ExampleCom" -Name MenuLastUpdate -Value "test" -Force
# Run ruby script when the container launches
CMD ["C:/Ruby23-x64/bin/ruby.exe", "docker_ruby_test.rb"]

Note that I am adding some registry entries to the Windows registry which the code inside the container will access.请注意,我正在向 Windows 注册表添加一些注册表项,容器内的代码将访问这些注册表项。 While this method of adding registry entries is fine for a few entries, my requirement is to add dozens of entries required for my windows application.虽然这种添加注册表项的方法对一些条目没问题,但我的要求是添加我的 windows 应用程序所需的数十个条目。 Is there a way to do this in a more concise manner?有没有办法以更简洁的方式做到这一点?

Try creating a file for the your registry entry and copy that inside the container. 尝试为您的注册表项创建文件,然后将其复制到容器中。

Then try running Invoke-Command -ScriptBlock {regedit /i /s C:\\shared\\settings.reg} 然后尝试运行Invoke-Command -ScriptBlock {regedit /i /s C:\\shared\\settings.reg}

The following is the only way I could getting working using 4.8-windowsservercore-ltsc2019以下是我使用4.8-windowsservercore-ltsc2019开始工作的唯一方法

COPY Registry/ChromeConfiguration.reg .

RUN reg import ChromeConfiguration.reg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM