# Target para fazer o build

```bash
$ docker image ls
REPOSITORY                                TAG          IMAGE ID       CREATED          SIZE
```

Dockerfile.multstage:

```docker
# IMAGEM INTERMEDIARIA
# imagem base nomeada como build
FROM golang:1.18.1 AS build
WORKDIR /build
COPY . .
# compilacao da aplicacao
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .

# IMAGEM FINAL
# imagem base nomeada como app
FROM alpine:3.20.2 AS app
WORKDIR /app
# copia do binario da imagem intermediaria (build) para a imagem final
COPY --from=build /build/main .
CMD ["./main"]
```

Execução somente da imagem intermediária BUILD:

```bash
$ docker image build -t marcelodpbarbieri/app-multi-stage 
                               -f Dockerfile.multistage --target=build .
[+] Building 6.6s (10/10) FINISHED                                                               docker:default
 => [internal] load build definition from Dockerfile.multistage                                            0.0s
 => => transferring dockerfile: 457B                                                                       0.0s
 => [internal] load metadata for docker.io/library/golang:1.18.1                                           1.5s
 => [auth] library/golang:pull token for registry-1.docker.io                                              0.0s
 => [internal] load .dockerignore                                                                          0.0s
 => => transferring context: 2B                                                                            0.0s
 => CACHED [build 1/4] FROM docker.io/library/golang:1.18.1@sha256:12d3995156cb0dcdbb9d3edb5827e4e8e1bf5b  0.0s
 => [internal] load build context                                                                          0.0s
 => => transferring context: 547B                                                                          0.0s
 => [build 2/4] WORKDIR /build                                                                             0.0s
 => [build 3/4] COPY . .                                                                                   0.0s
 => [build 4/4] RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .                      4.7s
 => exporting to image                                                                                     0.3s
 => => exporting layers                                                                                    0.2s
 => => writing image sha256:854ab5da955bf79c3b838a73b59ed4db39ad0c452fdbe4bc35e65502267bdaee               0.0s
 => => naming to docker.io/marcelodpbarbieri/app-multi-stage                                               0.0s
$ docker image ls
REPOSITORY                          TAG       IMAGE ID       CREATED         SIZE
marcelodpbarbieri/app-multi-stage   latest    854ab5da955b   3 seconds ago   1.02GB
```

Destaque para:

```bash
--target=build
```
