# Do the build. Script is part of incoming sources.
RUN build/build.sh
# STAGE 2: Deployment
FROM alpine
USER nobody:nobody
COPY --from=build /go/bin/kuard /kuard
CMD [ "/kuard" ]
该
Dockerfile
将产生两个镜像。第一是构建镜像,其中包含
Go
编译器、
React.js
工具链以及该程序的源代码。第二个是部署镜像,其中只包含编译好
的二进制文件。利用多阶段构建来构建容器镜像可以让最终的容器镜像缩小
数百兆,从而大幅加快部署速度,因为一般来说,部署的延迟主要取决于网
络性能。该
Dockerfile
生成的最终镜像大约为
20MB
。
你可以通过以下命令来构建和运行镜像:
$
docker build -t kuard .
$
docker run --rm -p 8080:8080 kuard
2.4
将镜像存储到远程仓库
如果容器镜像只能在一台计算机上使用,那么就大材小用了。
Kubernetes
的基础在于,
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.