We are using MsDeploy for deploying our site on IIS. When we publish we get three files, viz.
MySite.deploy.cmd,
MySite.SetParameters.xml
MySite.zip.
And we run a command like;
MySite.cmd /Y /M:https://IpOfMachine/MsDeploy.axd
to deploy on the server.
Now we want to move it to docker, with docker file something like this -
FROM microsoft/iis
RUN powershell -NoProfile -Command Remove-Item -Recurse
C:\inetpub\wwwroot*
WORKDIR C:/DeploymentFiles
COPY DeploymentPackage/ .
RUN cmd MySite.cmd /Y /M:https://IpOfDockerInstance/MsDeploy.axd
But the MsDeploy thing is not working and giving 404 error. I think I need to add WebDepoly to get this working, but how to do it in Docker?
Any suggestions, please. I am a novice to Docker
It could be difficult to get started with docker, if one's is not through well with the basics. I spent some time in reading out more on it and finally come up with the following Docker file that worked for me. I have tired to document the script inline with a couple of references that helped me.
FROM microsoft/iis
#Keep the artifacts related for image in the same folder from where docker is running
RUN cmd mkdir C:/DeploymentFiles
WORKDIR C:/DeploymentFiles
# Copy and install msdeploy service
COPY WebDeploy_amd64_en-US.msi .
RUN msiexec /i WebDeploy_amd64_en-US.msi AGREETOLICENSE=yes ADDLOCAL=ALL /qn
RUN powershell Start-service MsDepSvc;
#Remove default iis site's contents
RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*
# Resolving 403 issue. Ref - https://github.com/microsoft/iis-docker/issues/5
#Adding a user so i can connect trough IIS Manager
RUN NET USER testing "Password01!" /ADD
RUN NET LOCALGROUP "Administrators" "testing" /add
#Grant Permissions
RUN icacls "C:\inetpub\wwwroot\*" /grant everyone:(OI)(CI)F /T
#Install neccassary features
RUN powershell Install-WindowsFeature Web-Mgmt-Service
RUN powershell Install-WindowsFeature Web-Windows-Auth
RUN powershell Install-WindowsFeature NET-Framework-45-ASPNET
RUN powershell Install-WindowsFeature Web-Asp-Net45
RUN powershell Install-WindowsFeature NET-WCF-HTTP-Activation45
#Start Service and make it autorun
RUN net start wmsvc
RUN sc config WMSVC start= auto
RUN powershell -NoProfile -Command \
Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1
# Copy deployment packages and related files to container to "C:/DeploymentFiles"
COPY DeployPackage/ .
# The Deploy_App.bat file contains the command to deploy using msdeploy
COPY Deploy_App.bat .
RUN C:/DeploymentFiles/Deploy_App.bat
# Resolve the ACL issues during deployment. Ref - https://fluentbytes.com/how-to-fix-error-this-access-control-list-is-not-in-canonical-form-and-therefore-cannot-be-modified-error-count-1/
COPY aclFix.ps1 .
RUN powershell.exe -executionpolicy bypass .\aclFix.ps1
RUN C:/DeploymentFiles/Deploy_App.bat
EXPOSE 80
Related
I am trying to run my ASP.NET Web API on a docker container on Windows 2016 server. Here is my docker file:
FROM microsoft/dotnet-framework:4.7.2-sdk AS build
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.sln .
COPY TestWebAPI/*.csproj ./TestWebAPI/
COPY TestWebAPI/*.config ./TestWebAPI/
RUN nuget restore
# copy everything else and build app
COPY TestWebAPI/. ./TestWebAPI/
WORKDIR /app/TestWebAPI
RUN msbuild /p:Configuration=Release
FROM microsoft/iis:10.0.14393.206
RUN Remove-Website -Name 'Default Web Site'
RUN New-Website -Name 'TestWebApi' -Port 80 \
-PhysicalPath 'c:\app\TestWebAPI\' -ApplicationPool '.NET v4.5'
EXPOSE 80
CMD Write-Host IIS Started... ; \
while ($true) { Start-Sleep -Seconds 3600 }
I am using following commands to build the app:
docker image build --tag v2 --file .\Dockerfile .
After running the script, I am getting following error:
'Remove-Website' is not recognized as an internal or external command
I have seen few people using this command. What is the issue here?
Adding SHELL ["powershell"] fixed the issue.
FROM microsoft/dotnet-framework:4.7.2-sdk AS build
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.sln .
COPY TestWebAPI/*.csproj ./TestWebAPI/
COPY TestWebAPI/*.config ./TestWebAPI/
RUN nuget restore
# copy everything else and build app
COPY TestWebAPI/. ./TestWebAPI/
WORKDIR /app/TestWebAPI
RUN msbuild /p:Configuration=Release
FROM microsoft/iis:10.0.14393.206
SHELL ["powershell"]
COPY --from=build /app/TestWebAPI/. ./
RUN Remove-Website -Name 'Default Web Site'
RUN New-Website -Name 'TestWebApi' -Port 80 \
-PhysicalPath 'c:\appp\TestWebAPI\' -ApplicationPool '.NET v4.5'
EXPOSE 80
CMD Write-Host IIS Started... ; \
while ($true) { Start-Sleep -Seconds 3600 }
I am building a ASP.NET web API application running on .net framework 4.5. Here is my docker file:
FROM microsoft/dotnet-framework:4.7.2-sdk AS build
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.sln .
COPY TestWebAPI/*.csproj ./TestWebAPI/
COPY TestWebAPI/*.config ./TestWebAPI/
RUN nuget restore
# copy everything else and build app
COPY TestWebAPI/. ./TestWebAPI/
WORKDIR /app/TestWebAPI
RUN msbuild /p:Configuration=Release
FROM microsoft/iis:10.0.14393.206
SHELL ["powershell"]
WORKDIR /inetpub/wwwroot
COPY --from=build /app/TestWebAPI/. ./
RUN Remove-Website -Name 'Default Web Site'
RUN New-Website -Name 'TestWebApi' -Port 80 \
-PhysicalPath 'c:\inetpub\wwwroot' -ApplicationPool '.NET v4.5'
EXPOSE 80
CMD Write-Host IIS Started... ; \
while ($true) { Start-Sleep -Seconds 3600 }
Then i Run following commands:
docker image build --tag v7 --file .\Dockerfile .
docker container run --detach --publish 80 v7
docker ps to get the port number
When I go to specific port, the site does not load. There was no error while building containers. How can I find the issue (obviously its my docker file)
The command that is executed when running the container is
CMD Write-Host IIS Started... ; \
while ($true) { Start-Sleep -Seconds 3600 }
This obviously does not start the website as the steps executed with the RUN command are only executed during build time of the image.
I guess you meant to also execute the two steps executed within the build phase of the container with the RUN command. This can by achieved by either chaining them within the CMD step of the Dockerfile or by creating a small script wrapping these commands and executing it.
I am attempting to login to a Docker angular app using Identity Server for Authentication. Once I enter my credentials for on Identity Server, I get a 500 Internal Server Error.
When I run this application locally (non-Docker) I am able to login with ID Server and return to the Angular App without seeing any errors. Which makes me think there must be something wrong with my ID Server Dockerfile:
FROM microsoft/dotnet AS build-env
ARG source
RUN echo "source: $source"
WORKDIR /app
RUN apt-get update
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash
RUN apt-get install nodejs
RUN node -v
RUN npm -v
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
#Copy everything else & build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/dotnet
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 80
ENTRYPOINT ["dotnet", "IdentityServerWithAspNetIdentity.dll"]
Can anyone tell me why I am seeing a 500 Internal Server Error in Docker, and what I can do to resolve this issue?
Much appreciated, thank you.
I have created an image using the following script in my Dockerfile, but when I browse using the container's IP Address and port(2000), I get a 403 - Forbidden: Access is denied. I am using Windows 10.0.14393 Build 14393, Docker Desktop for Windows. The project is an ASP.NET solution containing Nancy, Entity Framework, AngularJS, and SQL Server projects. Do I need to make any configuration changes to my IIS, Docker, Powershell, etc.? My Dockerfile script is:
FROM microsoft/aspnet:windowsservercore
# using powershell commands
SHELL ["powershell"]
# location of the source directory
WORKDIR C:/src/Project
# run project using port 2000
RUN Remove-Website -Name 'Default Web Site'; \
New-Website -Name 'Project' -Port 2000 -PhysicalPath 'C:/src/Project'
Make sure that your files not ignore in .dockerignore
copy this Dockerfile
FROM microsoft/aspnet
WORKDIR /inetpub/wwwroot
COPY . /inetpub/wwwroot
# Give Full Access To Folder
RUN icacls 'c:/inetpub/wwwroot' /grant 'Everyone:(OI)(CI)F'
# Check that the files have been successfully copied
RUN dir
docker build -t test .
docker run -p 8001:80 test
Unfortunately it can be many things...
I had the same issue and the problem was that the /inetpub/wwwroot folder was empty.
I can see that you are adding a new website folder instead, but you can try:
My docker file is
# FROM microsoft/aspnet:4.7.1-windowsservercore-1709
FROM microsoft/aspnet:4.7.1-windowsservercore-ltsc2016
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} /inetpub/wwwroot
You can also try the solutions proposed in here:
https://github.com/Microsoft/iis-docker/issues/5
Cheers!
EDIT:
I also had issues when using localhost or 127.0.0.1. Use the public IP address
I'm currently trying to launch a Docker component with a ASP.NET Core application.
I use the following repo for my test : https://github.com/aspnet/cli-samples
I ran the following commande without any issue :
git clone https://github.com/aspnet/cli-samples aspnet-Home
cd aspnet-Home/HelloWeb
cat Dockerfile
FROM microsoft/aspnetcore
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "helloweb.dll"]
sudo docker build –t helloweb .
sudo docker run -d helloweb
The image is visible using the sudo docker images, but the container doesn't launch and is not visible with sudo docker ps:
And if I browse my website, obsviously I do not see data.
Is the repo not good for my test ? Is there any mistake I do on the docker container creation ?
Running the -it command give me the following output:
The error you highlighted is because helloweb.dll you set as the ENTRYPOINT doesn't exist. There could be two reasons for it
1 You didn't build the project yet
In this case you should run dotnet restore from the project home directory, then navigate to HelloWeb directory and run dotnet publish. When I run this command, I see the following:
publish: Published to /code/HelloWeb/bin/Debug/netcoreapp1.0/publish
Published 1/1 projects successfully
2 You built the project, but the ENTRYPOINT path is wrong
COPY . . directive will copy everything from the current directory into your app directory. That means HelloWeb.dll will actually be in bin/Debug/netcoreapp1.0/publish/ (or bin/Release/... for release builds).
Option 1: Modify your entrypoint with the full path
ENTRYPOINT ["dotnet", "bin/Debug/netcoreapp1.0/publish/HelloWeb.dll"]
Your application should happily start and serve requests.
Option 2: Modify your COPY directive
Once your project has been published, everything you'll need to run it will be in the publish directory. You could copy the contents of that into the /app directory and your entrypoint will be correct. That would look like this
FROM microsoft/aspnetcore
WORKDIR /app
COPY ./bin/Debug/netcoreapp1.0/publish/ .
EXPOSE 80
ENTRYPOINT ["dotnet", "HelloWeb.dll"]
You will also probably want to add the EXPOSE directive to tell Docker that your container will be listening on port 80.
When that succeeds, you should see (if you run in interactive mode)
docker run -it helloweb
Hosting environment: Production
Content root path: /app
Now listening on: http://+:80
Application started. Press Ctrl+C to shut down.
You could also use the microsoft/dotnet:latest image instead. That image comes with the SDK installed and a very convenient run command. The Dockerfile would look like this
FROM microsoft/dotnet:latest
COPY . /app
WORKDIR /app
RUN dotnet restore
ENV ASPNETCORE_URLS http://*:5000
EXPOSE 5000
ENTRYPOINT ["dotnet", "run"]
and you should be able to modify your source and build and run your container.