如何直接从构建步骤创建 docker 镜像 tar?
我想创建一个可共享的映像,可以直接从 docker build 中 docker load 到另一个 docker 安装中,
例如
Dockerfile:
FROM my-app/env as builder
COPY /my-app /my-app
RUN /my-app/build.sh
FROM ubuntu:20.04
COPY --from=builder /my-app/build/my-app.exe /bin
RUN DEBIAN_FRONTEND=noninteractive apt-get update \
&& apt-get install -y --no-install-recommends \
***some stuff required at runtime*** \
&& apt-get autoclean \
&& apt-get autoremove \
&& ldconfig
ENTRYPOINT ["my-app.exe"]
CMD ["--help"]
运行类似的内容:
/my-app$ docker build -t my-app/exe .
将生成一个我可以使用的映像如果
$ docker run my-app/exe
我现在想共享此内容,我需要执行以下操作:
$ docker save -o my-app.tar my-app/exe
创建存档 my-app.tar
,该存档可以与运行相同 arch/OS 的另一个系统共享并由以下人员使用:
/my-othersystem/my-app$ docker load < my-app.tar
现在
$ docker run my-app/exe
可以使用在另一个系统上。
但是
这需要将映像构建到构建系统 Docker 存储库中,然后将映像保存到文件中。我不打算在构建系统上运行可执行文件,因此不希望它占用空间。
你可以这样做:
/my-app$ DOCKER_BUILDKIT=1 docker build --output type=tar,dest=out.tar .
但这会创建一个 FS,而不是一个镜像。我希望将其导出为直接与 docker load 兼容的 docker 镜像,这可能吗?
I want to create a shareable image which can be docker load
ed into another docker installation directly from docker build
e.g.
Dockerfile:
FROM my-app/env as builder
COPY /my-app /my-app
RUN /my-app/build.sh
FROM ubuntu:20.04
COPY --from=builder /my-app/build/my-app.exe /bin
RUN DEBIAN_FRONTEND=noninteractive apt-get update \
&& apt-get install -y --no-install-recommends \
***some stuff required at runtime*** \
&& apt-get autoclean \
&& apt-get autoremove \
&& ldconfig
ENTRYPOINT ["my-app.exe"]
CMD ["--help"]
Running something like:
/my-app$ docker build -t my-app/exe .
will produce an image which I can use with
$ docker run my-app/exe
If I want to now share this, I need to do:
$ docker save -o my-app.tar my-app/exe
which creates the archive my-app.tar
which can be shared with another system running the same arch/OS and used by:
/my-othersystem/my-app$ docker load < my-app.tar
And
$ docker run my-app/exe
now works on the other system.
HOWEVER
This requires building the image into the build system docker repository then saving the image to a file. I don't plan to run the exeutable on the build system so don't want it taking up space.
You can do:
/my-app$ DOCKER_BUILDKIT=1 docker build --output type=tar,dest=out.tar .
But this creates a FS, not an image. I want it to be exported as a docker image compatible with docker load
directly, is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论