0

I have a Dockerfile as following:

# Install Operating system and dependencies
FROM ubuntu:22.04 AS build-env

RUN apt-get update 
RUN apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback lib32stdc++6 python3
RUN apt-get clean

RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/user

# download Flutter SDK from Flutter Github repo
RUN git clone https://github.com/flutter/flutter.git /usr/local/flutter

# Set flutter environment path
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}"

# Run flutter doctor
RUN flutter doctor

# Enable flutter web
RUN flutter channel master
RUN flutter upgrade
RUN flutter config --enable-web

# Copy files to container and build
RUN mkdir /app/
COPY . /app/
WORKDIR /app/
RUN flutter build web


# Stage 2 - Create the run-time image
FROM nginx:1.21.1-alpine
COPY --from=build-env /app/build/web /usr/share/nginx/html

I am wondering to know what does the lase part(stage 2) do?

best_of_man
  • 367
  • 1
  • 3
  • 12
  • 1
    Have you looked into various documentation pages uncovered by a google search. FOr example, [this](https://docs.docker.com/engine/reference/builder/) page documents the COPY directive in a dockerfile fairly well. – doneal24 Jan 15 '23 at 20:30
  • @doneal24: I meant why they do that? I know how the `COPY` statement works. – best_of_man Jan 15 '23 at 20:43
  • You asked 'what does the last part do"? As to why the authors of the dockerfile include that line, you will have to ask them. – doneal24 Jan 15 '23 at 21:01

1 Answers1

2

This is a common pattern where you have a builder image which contains tools, SDKs, etc and then a minimal runtime image with no development dependencies.

In this case, the first image is is used to actually build the Flutter application (you can see where it adds some OS dependencies via apt-get and then clones the Flutter SDK). It then builds a web application ("--enable-web") and outputs it in the "/app/build/web".

Now that the web artifacts are built, you only need a minimal image with a web server (in this case "nginx") and the build artifacts. So stage 2 does exactly this: minimal nginx container plus the web artifacts built in stage 1.

Gari Singh
  • 131
  • 3