Imagem externa no Multistage build
Além de copiar imagens que fazem parte das imagens intermediárias é possível copiar arquivos de outras imagens inclusive repositórios remotos.
Criação de uma imagem para armazenar o pacote binário:
$ pwd
/tmp/pacote
$ touch pacote.bin
$ vim pacote.bin
$ cat pacote.bin
Binário
$ touch Dockerfile
$ vim Dockerfile
$ cat Dockerfile
FROM alpine:3.20.2
WORKDIR /pkg
COPY . .
$ docker image build -t marcelodpbarbieri/pacote-bin -f Dockerfile .
[+] Building 3.5s (9/9) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 78B 0.0s
=> [internal] load metadata for docker.io/library/alpine:3.20.2 2.7s
=> [auth] library/alpine:pull token for registry-1.docker.io 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/3] FROM docker.io/library/alpine:3.20.2@sha256:0a4eaa0eecf5f8c050e5bba433f58c052be7587ee8af3e8b3910ef9ab5fb 0.5s
=> => resolve docker.io/library/alpine:3.20.2@sha256:0a4eaa0eecf5f8c050e5bba433f58c052be7587ee8af3e8b3910ef9ab5fb 0.0s
=> => sha256:c6a83fedfae6ed8a4f5f7cbb6a7b6f1c1ec3d86fea8cb9e5ba2e5e6673fde9f6 3.62MB / 3.62MB 0.4s
=> => sha256:0a4eaa0eecf5f8c050e5bba433f58c052be7587ee8af3e8b3910ef9ab5fbe9f5 1.85kB / 1.85kB 0.0s
=> => sha256:eddacbc7e24bf8799a4ed3cdcfa50d4b88a323695ad80f317b6629883b2c2a78 528B / 528B 0.0s
=> => sha256:324bc02ae1231fd9255658c128086395d3fa0aedd5a41ab6b034fd649d1a9260 1.47kB / 1.47kB 0.0s
=> => extracting sha256:c6a83fedfae6ed8a4f5f7cbb6a7b6f1c1ec3d86fea8cb9e5ba2e5e6673fde9f6 0.1s
=> [internal] load build context 0.0s
=> => transferring context: 126B 0.0s
=> [2/3] WORKDIR /pkg 0.0s
=> [3/3] COPY . . 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.0s
=> => writing image sha256:04018fdd126926818c26277636375115b46c41bccb00668af58a0fcf4b8654b8 0.0s
=> => naming to docker.io/marcelodpbarbieri/pacote-bin 0.0s
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
marcelodpbarbieri/pacote-bin latest 04018fdd1269 24 seconds ago 7.8MB
$ docker image push marcelodpbarbieri/pacote-bin
Using default tag: latest
The push refers to repository [docker.io/marcelodpbarbieri/pacote-bin]
dbbf66204e71: Pushed
289d56dfbc63: Pushed
78561cef0761: Mounted from marcelodpbarbieri/conversao-temperatura
latest: digest: sha256:d8eda8c30cd5bfaa0dcce6b903496c1415c849a9c351f6016ef845591ca44651 size: 940
$ docker container run -it marcelodpbarbieri/pacote-bin /bin/sh
/pkg # ls
Dockerfile pacote.binConstrução da imagem final com referência ao pacote.bin da imagem remota.
Dockerfile:
Destaque para:
Construção da imagem final:
Destaque para:
Teste da aplicação:

Acessar o container:
Last updated