Develop Intelligence - Docker Multi-Stage Builds: #Build Stage Build-Env
Develop Intelligence - Docker Multi-Stage Builds: #Build Stage Build-Env
Multi-Stage Builds
Multi-stage builds are a new feature requiring Docker 17.05 or higher on the daemon and client.
Before the multi-stage build feature was added, a script was required to copy the published output of your
build container onto your disk and then the runtime container would read in that output. This was tedious to
implement and not super-efficient. Now, containers can share build artifacts from different stages within a
single Dockerfile.
Using this feature, you can build a .NET Core app in an SDK image and then copy the published app into a
runtime image all in the same Dockerfile.
Example:
#Build Stage
WORKDIR /src
COPY *.csproj .
COPY . .
WORKDIR /out
WORKDIR /app
NOTE: You can name your stages, by adding an AS to the FROM instruction.By default, the stages are not named,
and you can refer to them by their integer number, starting with 0 for the first FROM instruction.
FROM openjdk:11-jre-slim
WORKDIR /app
COPY --from=base /HelloWorld/bin/demo/*.class ./demo/
ENTRYPOINT ["java", "demo.HelloWorld"]
FROM python:3.9.1-slim-buster
WORKDIR /app
COPY --from=base /app/__pycache__/*.pyc .
CMD ["python", "hello.cpython-39.pyc"]