trying to create Dockerfile for my .net framework web project
FROM mcr.microsoft.com/dotnet/framework:4.8-sdk As builder
WORKDIR D:\src
COPY *.sln .
COPY Internal.Api.csproj .\Internal.Api\
RUN nuget restore
COPY . D:\src
RUN msbuild Internal.Api.csproj /p:OutputPath=d:\out /p:Configuration=Release
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019
SHELL ["powershell", "-Command", "$ErrorActionPreference='Stop';"]
ENV APP_ROOT=D:\web-app
WORKDIR ${APP_ROOT}
RUN Remove-Website -Name 'Default Web Site';`
New-Website -Name 'web-app' -Port 80 -PhysicalPath $env:APP_ROOT;`
New-WebApplication -Name 'app' -Site 'web-app' -PhysicalPath $env:APP_ROOT`
COPY --from=builder D:\out\-PublishedWebsites\Internal.Api .
But getting following error
You need to tell Docker that the command continues on the next line by adding \ at the end. Not the back-ticks that you're using now. Like this
RUN Remove-Website -Name 'Default Web Site'; \
New-Website -Name 'web-app' -Port 80 -PhysicalPath $env:APP_ROOT; \
New-WebApplication -Name 'app' -Site 'web-app' -PhysicalPath $env:APP_ROOT
Related
I need to use mcr.microsoft.com/windows:10.0.17763.2928 docker image. How to install .net framework v4.8 into this container? I use following docker file. I upload ndp48-x86-x64-allos-enu.exe (.net framework v4.8 installer) into container, and then install it by command line, but it doesn't work. I got the "404 - File or directory not found."
FROM mcr.microsoft.com/windows:10.0.17763.2928
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45 -All
WORKDIR c:/
COPY ndp48-x86-x64-allos-enu.exe .
RUN Start-Process -FilePath 'C:/ndp48-x86-x64-allos-enu.exe' -ArgumentList '/quiet', '/NoRestart', '/L*V C:/net48log.log' -Wait
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
I need to execute a shell script from within Docker. I am not as proficient in Docker or in scripting as I would like to be. The script has no effect and does not print anything to the screen. I do not believe that it is being called.
What am I doing wrong here?
The script should be run as the entrypoint command.
The Script
#!/usr/bin/env bash
set -Ex
function apply_path {
echo "Check that we have ENVIRONMENT_VAR vars"
test -n "$ENVIRONMENT_VAR"
find /usr/src/app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#NEXT_PUBLIC_ENVIRONMENT_VAR#$ENVIRONMENT_VAR#g"
}
apply_path
echo "Starting Nextjs"
exec "$#"
The docker file
ARG NODE_VERSION=14.4.0-alpine
###
# STAGE 1: Base
###
FROM node:$NODE_VERSION as base
ENV NODE_PATH=/src
WORKDIR $NODE_PATH
###
# STAGE 2: Build
###
FROM base as build
COPY package.json package-lock.json .npmrc ./
RUN npm i
COPY . ./
RUN NEXT_PUBLIC_ENVIRONMENT_VAR=BUILD npm run build
# Permisions to execute script
RUN ["chmod", "+x", "./entrypoint.sh"]
ENTRYPOINT ["./entrypoint.sh"]
###
# STAGE 3: Production
###
FROM node:$NODE_VERSION
ENV NODE_PATH=/src
ENV APP_PORT=3000
WORKDIR $NODE_PATH
COPY --from=build $NODE_PATH/.next ./.next
COPY --from=build $NODE_PATH/node_modules ./node_modules
COPY --from=build $NODE_PATH/src ./src
COPY --from=build $NODE_PATH/package.json ./
COPY --from=build $NODE_PATH/.babelrc ./
COPY --from=build $NODE_PATH/LICENSE ./
EXPOSE $APP_PORT
CMD npm start
When you have a multi-stage Docker build, the end result of that is only the results starting from the final FROM line. While you're setting that script as an ENTRYPOINT, it's in a previous build stage that's not getting used. ENTRYPOINT (and CMD) don't run at image build time, only when the built image is eventually run.
The easiest way to address this is to COPY the script directly into the final build stage:
# STAGE 3: Production
FROM node:$NODE_VERSION
...
COPY entrypoint.sh .
ENTRYPOINT ["./entrypoint.sh"]
CMD npm start
I am new to the containers and have created a Windows Docker image which is running fine locally as https://localhost but when I published the image on Docker Hub and tried to use in Web App Container its failing with the error message: Unable to start container. Error message: Open Compute System failed.
This is my Dockerfile
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019
ARG source
WORKDIR /inetpub/wwwroot
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
RUN Install-WindowsFeature NET-Framework-45-ASPNET ; "\
Install-WindowsFeature Web-Asp-Net45; \
Invoke-WebRequest -UseBasicParsing -Uri "https://dotnetbinaries.blob.core.windows.net/servicemonitor/2.0.1.6/ServiceMonitor.exe" -OutFile "C:\ServiceMonitor.exe"
#Expose port 443 to allow incoming traffic over the default HTTPS port
EXPOSE 443
#create a folder on the container to hold the code
RUN powershell -Command \
New-Item -Path sampleaspnet -ItemType Directory
#Set the newly created folder in docker as the working directory for subsequent commands
WORKDIR 'C:\inetpub\wwwroot\sampleaspnet'
#Copy everything from where you are on host to the working directory in docker (this folder should contain your SSL cert)
COPY ./bin/Release/PublishOutput/ .
COPY IIS_Docker.pfx .
RUN powershell.exe -Command "\
Import-Module IISAdministration; \
Import-Module WebAdministration; \
Remove-Website -Name 'Default Web Site'; \
New-Website -Name 'sampleaspnet' -IPAddress '*' -Port 443 -PhysicalPath 'C:\inetpub\wwwroot\sampleaspnet' -ApplicationPool '.NET v4.5' -Ssl -SslFlags 0; \
#If you have a password on your SSL Cert, put it here as it needs "secured". If not, remove this line and the argument below it; \
$pwd = ConvertTo-SecureString -String 'admin123456' -Force -AsPlainText; \
#Import the certificate and store it in a variable to bind to later; \
$cert = Import-PfxCertificate -Exportable -FilePath 'IIS_Docker.pfx' -CertStoreLocation cert:\localMachine\My -Password $pwd; \
#Take the imported certificate and bind it to all traffic toward port 443 (you need to specify IP if you want multiple apps on 1 docker which I believe is ill-advised); \
New-Item -Path IIS:\SslBindings\0.0.0.0!443 -value $cert;"
Check the container logs but an Open Compute System Failed is could indicate a problem retrieving and running your image. There is a timeout for loading the image and mounting the backend storage.
Your docker file is doing a lot that's unnecessary though. Your base image is a cached image, which is good because that means images aren't being pulled from fresh. But mcr.microsoft.com/dotnet/framework/aspnet:4.8 already has IIS, .NET 4.5 (through .NET 4.8), and IIS extensibility. You don't need to expose 443 because the app service will bind a port on your image to route HTTP traffic as necessary. You also don't need to configure a SSL certificate as you'll configure that on the app service as well.
Have a look at this Dockerfile for how you can configure your image with your .NETFX application but I would start with the following:
EDIT: Here's my complete dockerfile.
# image for building our app
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS build
WORKDIR /app
# copy the project files
COPY *.sln .
COPY DemoForms.Web/*.csproj ./DemoForms.Web/
COPY DemoForms.Web/*.config ./DemoForms.Web/
RUN nuget restore
# build it
COPY DemoForms.Web/. ./DemoForms.Web/
WORKDIR /app/DemoForms.Web
RUN msbuild /p:Configuration=Debug
# and run it
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019 as runtime
WORKDIR /inetpub/wwwroot
COPY --from=build /app/DemoForms.Web/. ./
We have an angular app we are trying to run in docker nginx.
I have to run a script on startup that uses an environment variableto replace the app url for each stage. This is needed to connect to the backend.
We do not wish to build the container for each stage. The container will run in Azure docker.
For now i am running it locally. It executes my script and then the app shuts down.
The Docker File:
FROM node:8.11.2-alpine as node
LABEL author="My Online Presence"
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:1.13.12-alpine
COPY /certificates /etc/nginx/
COPY --from=node /usr/src/app/dist /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
ADD run.sh /usr/share/nginx/html/run.sh
RUN apk add --update bash && rm -rf /var/cache/apk/*
RUN chmod +x /usr/share/nginx/html/run.sh
ENTRYPOINT ["/usr/share/nginx/html/run.sh"]
CMD ["nginx", "-g", "daemon off;"]
The run.sh file
#!/bin/sh
FILE_NAME=$(find . -name "main*.js")
sed -i "s/localhost\:4200/${DIGITISE_URL}/g" $FILE_NAME
echo 'File updated with correct url'
i use
docker build -t digitise .
and then
docker run -p 80:80 -p 443:443 -e DIGITISE_URL=digitise.co.za digitise
I got it working simply by adding
exec "$#"
to the end of my script being run
You can also start nginx service in your script.
Using the following docker file I am getting an error on RUN md $SiteFolderPath and I am not sure why every example I look at:
https://docs.docker.com/engine/reference/builder/#environment-replacement
Indicates I am doing it correctly.
FROM microsoft/iis
#FROM nanoserver/iis
SHELL ["powershell"]
ENV SiteFolderPath c:\\app
ENV SiteFolderPathLogs c:\\app\\logs
ENV WorkFolder /app
ENV SiteAppPool LocalAppPool
ENV SiteName LocalWebSite
ENV SiteHostName LocalSite
RUN md $SiteFolderPath
RUN md $SiteFolderPathLogs
WORKDIR $WorkFolder
COPY ./Public .
RUN New-Item $SiteFolderPath -type Directory
RUN Set-Content $SiteFolderPath\Default.htm "<h1>Hello IIS</h1>"
RUN New-Item IIS:\AppPools\$SiteAppPool
RUN New-Item IIS:\Sites\$SiteName -physicalPath $SiteFolderPath -bindings #{protocol="http";bindingInformation=":80:"+$SiteHostName}
RUN Set-ItemProperty IIS:\Sites\$SiteName -name applicationPool -value $SiteAppPool
EXPOSE 80
EXPOSE 443
VOLUME ${SiteFolderPathLogs}
I get an error message when building the docker file:
mkdir : Cannot bind argument to parameter 'Path' because it is null.
The page you linked to states:
Environment variables are supported by the following list of instructions in the Dockerfile:
ADD
COPY
ENV
EXPOSE
FROM
LABEL
STOPSIGNAL
USER
VOLUME
WORKDIR
as well as:
ONBUILD (when combined with one of the supported instructions above)
Since you are using the variables as part of a RUN block, you should use the Windows environment variable syntax: %SiteFolderPath%