Reputation: 1636
So, I have a docker container ready for building, but, when I build it, I need to go manualy and start mongod from within docker container. What am I doing wrong? I start the mongod from the Dockerfile, but it looks like that something is killing the process or that the process is never even being executed?
FROM microsoft/iis:10.0.14393.206
SHELL ["powershell"]
RUN Install-WindowsFeature NET-Framework-45-ASPNET ; \
Install-WindowsFeature Web-Asp-Net45
COPY Pub Pub
RUN mkdir data\db
COPY mongodb_installer.msi mongodb_installer.msi
RUN Start-Process -FilePath 'mongodb_installer.msi' -ArgumentList '/quiet', '/NoRestart' -Wait ; \
Remove-Item .\mongodb_installer.msi
RUN 'C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe'
RUN Remove-WebSite -Name 'Default Web Site'
RUN New-Website -Name 'Pub' -Port 80 \
-PhysicalPath 'C:\Pub' -ApplicationPool '.NET v4.5'
EXPOSE 80
CMD ["ping", "-t", "localhost"]
When I start mongod from withing container, my web api application is working perfectly, need to know how to set mongod running from start?
Upvotes: 1
Views: 421
Reputation: 1636
So, going in the right direction with the answer provided by @Peri461, this made it work at the end:
FROM microsoft/iis:10.0.14393.206
SHELL ["powershell"]
RUN Install-WindowsFeature NET-Framework-45-ASPNET ; \
Install-WindowsFeature Web-Asp-Net45
COPY Pub Pub
RUN mkdir data\db
COPY mongodb_installer.msi mongodb_installer.msi
RUN Start-Process -FilePath 'mongodb_installer.msi' -ArgumentList '/quiet', '/NoRestart' -Wait ; \
Remove-Item .\mongodb_installer.msi
RUN Remove-WebSite -Name 'Default Web Site'
RUN New-Website -Name 'Pub' -Port 80 \
-PhysicalPath 'C:\Pub' -ApplicationPool '.NET v4.5'
ADD init.bat init.bat
ENTRYPOINT C:\init.bat
EXPOSE 80
CMD ["ping", "-t", "localhost"]
Entrypoint should point to the batch that should be executed when container starts. After that, just start the container like:
docker run --name pub -d -p 80:80 pub
Upvotes: 2
Reputation:
I tried this too myself at one point. What I found is that you can't actually start processes from the Dockerfile. It seems natural to make a Docker image by giving it all of the install commands for a certain program, but it's not yet a running instance when you're building the image.
The solution if I remember correctly, is to use an ENTRYPOINT
statement in your Dockerfile, so that it'll execute these commands at runtime and not build-time.
This might make an interesting follow-up to read.
And here is the documentation Docker has for the ENTRYPOINT
statement.
Upvotes: 1