本文介绍了多个镜像,一个 Dockerfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在一个 Dockerfile 中创建两个镜像,它们只复制不同的文件.
How to create two images in one Dockerfile, they only copy different files.
这不应该产生两个图像img1 &img2,而是生成两个未命名的图像 d00a6fc336b3 &a88fbba7eede
Shouldn't this produce two images img1 & img2, instead it produces two unnamed images d00a6fc336b3 & a88fbba7eede
Dockerfile:
Dockerfile:
FROM alpine as img1
COPY file1.txt .
FROM alpine as img2
COPY file2.txt .
这是 docker build 的结果.
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> d00a6fc336b3 4 seconds ago 4.15 MB
<none> <none> a88fbba7eede 5 seconds ago 4.15 MB
alpine latest 3fd9065eaf02 3 months ago 4.15 MB
推荐答案
你可以使用 target 的 code>docker-compose
文件 选项:
You can use a docker-compose
file using the target
option:
version: '3.4'
services:
img1:
build:
context: .
target: img1
img2:
build:
context: .
target: img2
使用带有以下内容的 Dockerfile
:
using your Dockerfile
with the following content:
FROM alpine as img1
COPY file1.txt .
FROM alpine as img2
COPY file2.txt .
这篇关于多个镜像,一个 Dockerfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!