Dockerfile
is a text file that defines the environment
FROM ubuntu
FROM scratch
can be used instead.docker build -t container-name .
in folder where Dockerfile existsdocker run -d -p 8080:80 --name app-name container-name
docker ps
&&
to avoid creating additional layers.
RUN
instruction creates a new layer in the container imageE.g. with using \
to wrap lines:
RUN powershell.exe -Command \
$ErrorActionPreference = 'Stop'; \
Invoke-WebRequest https://www.python.org/ftp/python/3.5.1/python-3.5.1.exe -OutFile c:\python-3.5.1.exe ; \
Start-Process c:\python-3.5.1.exe -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1' -Wait ; \
Remove-Item c:\python-3.5.1.exe -Force
build.sh
was used to copy contents from one docker image to another. FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env # from docker hub, good to name with AS for flexible re-ordering
WORKDIR /app # create directory
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.mcrosoft.com/dotnet/core/aspnet:2.2 # for running application
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "serverappname.dll"]
Dockerfile
as multiple stage build