Score:0

What does "COPY --from=build-env /app/build/web /usr/share/nginx/html" do?

pl flag

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?

jm flag
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.
best_of_man avatar
pl flag
@doneal24: I meant why they do that? I know how the `COPY` statement works.
jm flag
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.
Score:2
cn flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.