我是docker的新手,我正在尝试让Nexus3在windows容器中运行。
我的机器运行的是Windows10,我使用的是: Docker CE version17.03.1-ce-win12 (12058)频道:稳定的d1db126
我有以下DockerFile内容。
FROM microsoft/nanoserver
#FROM microsoft/windowsservercore # I also tried this as the base image in case something was missing that I needed.
EXPOSE 8081
ADD /content /nexus3
WORKDIR \\nexus3\\nexus-3.3.1-01-win64\\nexus-3.3.1-01\\bin
RUN ["nexus.exe", "/install", "nexus3"]
RUN ["nexus.exe", "/start", "nexus3"]
RUN ["powershell", "-Command", "Get-Service", "nexus3"]内容文件夹树看起来像这样,只是已经解压的windows的nexus3下载。
B:\Docker\nexus\content
==> tree /A
B:.
\---nexus-3.3.1-01-win64
+---nexus-3.3.1-01
| +---.install4j
| +---bin
| +---deploy
| +---etc
| +---jre
| +---lib
| +---public
| \---system
\---sonatype-work构建容器时,它会显示服务已安装并已启动。我已经使用Get-Service nexus3确认了这一点。以下是构建输出:
B:\docker\nexus
==> docker build -t nexus3 .
Sending build context to Docker daemon 222 MB
Step 1/7 : FROM microsoft/nanoserver
---> 6c367cf4cb98
Step 2/7 : EXPOSE 8081
---> Running in 047d556668ac
---> 6478e2faf841
Removing intermediate container 047d556668ac
Step 3/7 : ADD /content /nexus3
---> caacf937e885
Removing intermediate container cb601d94cd4a
Step 4/7 : WORKDIR \\nexus3\\nexus-3.3.1-01-win64\\nexus-3.3.1-01\\bin
---> d0e1afd3d105
Removing intermediate container 201e369a32de
Step 5/7 : RUN nexus.exe /install nexus3
---> Running in 61516df89010
Installed service 'nexus3'.
---> bbfff0f34205
Removing intermediate container 61516df89010
Step 6/7 : RUN nexus.exe /start nexus3
---> Running in ff274ef81a91
Service is already running.
---> ba20f07a47ce
Removing intermediate container ff274ef81a91
Step 7/7 : RUN powershell -Command Get-Service nexus3
---> Running in 3c8c767a56fd
Status Name DisplayName
------ ---- -----------
Running nexus3 nexus3
---> ef166720c132
Removing intermediate container 3c8c767a56fd
Successfully built ef166720c132到目前一切尚好。现在,我使用以下命令运行镜像:
docker run -it nexus3 powershell现在,从容器内部使用powershell终端,检查服务是否正在运行:
Get-Service nexus3
Status Name DisplayName
------ ---- -----------
Stopped nexus3 nexus3所以我运行了下面的代码,但它讨厌我!;-)
Start-Service nexus3
Start-Service : Failed to start service 'nexus3 (nexus3)'.
At line:1 char:1
+ Start-Service nexus3
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service], ServiceCommandException
+ FullyQualifiedErrorId : StartServiceFailed,Microsoft.PowerShell.Commands.StartServiceCommand如果我错了,现在纠正我,但是我应该在容器中有一个管理员powershell,因为"docker run -it“开关,因此这应该不是启动服务的权限问题。
我还检查了该服务是否设置为自动运行,并且没有问题:
==>$(Get-Service nexus3).StartType
Automatic有人知道我做错了什么吗?该服务在构建时启动,但在我运行它时无法启动,这一事实表明我遗漏了一些东西,但我无法弄清楚。
发布于 2017-05-23 01:08:56
实际上,容器内的用户应该具有管理员权限,因此您可能希望检查是否阻止了其他内容,如端口。我不熟悉Nexus,但是你知道在哪里可以找到日志目录吗?它可能会为您提供其他阻塞服务的信息。
此外,许多公司已经开始在GitHub上使用容器,所以我通常会在那里寻找现有的图像。
事实上,快速的谷歌搜索显示了这一点。也许,这就是你需要的?
发布于 2019-03-29 03:45:25
我会将您的入口点更改为:
nexus.exe /run下面是我用来构建/运行容器的docker文件。
有一件事需要注意,因为Java不喜欢docker使用的symlink,并且在尝试存储blob并将db定向到它爆炸的容器之外时,它会尝试转到实际路径。
为了解决这个问题,我使用DOS设备并将数据路径设置为G:,然后我可以将目录挂载到主机外部,以备份定向数据库和blobs。
#### Build container
FROM mcr.microsoft.com/windows/nanoserver:sac2016 as installer
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
WORKDIR C:\\nexus
RUN Write-Host "Downloading nexus..."; \
Invoke-WebRequest "http://download.sonatype.com/nexus/3/latest-win64.zip" -OutFile 'C:\nexus\nexus.zip' -UseBasicParsing
RUN Expand-Archive 'nexus.zip' -DestinationPath 'C:\nexus'
RUN Remove-Item -Path 'C:\nexus\*.zip' -Filter '*.zip' -Force
RUN Get-ChildItem -Path 'C:\nexus' -Filter 'nexus-*' -Directory | Rename-Item -NewName 'nexus_root' -Force
COPY nexus.vmoptions /nexus/nexus_root/bin
#### Runtime Container
FROM mcr.microsoft.com/windows/nanoserver:sac2016
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
EXPOSE 8081
WORKDIR C:\\nexus
ENTRYPOINT C:\nexus\nexus_root\bin\nexus.exe /run
COPY --from=installer C:\\nexus .
RUN MKDIR c:\\data
RUN Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices' -Name 'G:' -Value "\??\C:\data" -Type String 下面是我的nexus.vmoptions的用法:
-Xms1200M
-Xmx1200M
-XX:MaxDirectMemorySize=2G
-XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass
-XX:+LogVMOutput
-XX:LogFile=../sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=g:/data
-Djava.io.tmpdir=g:/tmp
-Dkaraf.startLocalConsole=false
-Dorg.eclipse.jetty.LEVEL=DEBUG然后我就用以下命令进行构建
docker build --tag nexus-img . 并以以下内容开始
docker run -d --name nexus --mount type=bind,source=C:\hostdata,target=C:\data -p 80:8081 nexus-img 我的数据和日志最终保存在主机上的C:\hostdata中。
https://stackoverflow.com/questions/44071529
复制相似问题