我设置了一个Windows docker镜像,并在我的Windows 10机器上启动它 . 在运行的docker镜像中,在我的gitlab服务器上注册了gitlab runner . 问题是gitlab服务器看到了主机Windows机器的IP地址,因此它是在线的东西 .

无论如何在交互式docker镜像中运行构建运行器?

这是我的dockerfile

# escape=`

FROM microsoft/windowsservercore

RUN @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

# wait for vs_installer.exe, vs_installerservice.exe
# or vs_installershell.exe because choco doesn't
RUN powershell -NoProfile -InputFormat None -Command `
    choco install git 7zip -y; `
    choco install visualcpp-build-tools `
            -y; `
    Write-Host 'Waiting for Visual C++ Build Tools to finish'; `
    Wait-Process -Name vs_installer

#WORKDIR C:\build
#CMD powershell -ExecutionPolicy Bypass -Command .\release.ps1

COPY entrypoint.bat entrypoint.bat

# Install Chocolatey
#RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET #"PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"    

# Register the GitLab Runner
COPY gitlab-runner-windows-amd64.exe /gitlab/gitlab-runner.exe
RUN /gitlab/gitlab-runner.exe install

SHELL ["cmd.exe", "/s", "/c", "C:\\entrypoint.bat"]

WORKDIR /code

ENTRYPOINT ["C:\\entrypoint.bat"]
CMD ["cmd"]

EXPOSE 443

和我的entrypoint.bat文件

@echo off
pushd C:
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat"
REM call "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
popd
%*

这是我如何构建它

docker build -t windows .

这是我如何运行它

docker run -it windows cmd

这是我如何注册gitlab跑步者

C:\gitlab>gitlab-runner register --non-interactive --name "Windows docker builder" --url "https://gitlabserver/" --registration-token TOKEN --tag-list windows --executor shell
Registering runner... succeeded                     runner=XXX
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

在GitLab服务器上,我可以看到它是寄存器,但是它显示了Windows 10主机的IP地址而不是docker里面的ip地址 .
enter image description here