在docker build中运行docker命令 [英] Running a docker command in docker build

查看:77
本文介绍了在docker build中运行docker命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用docker构建自身的应用程序,我想为其构建docker映像.这需要在 docker build 命令期间将 docker.sock 暴露给应用程序(类似于添加 -v/var/run/run/docker.sock:/var/run/docker.sock 参数传递给 docker run 命令).

I have an application which uses docker to build itself, and I want to build a docker image of it. This requires exposing the docker.sock to the application during the docker build command (similar to adding a -v /var/run/docker.sock:/var/run/docker.sock argument to a docker run command).

有什么方法可以做到这一点,还是应该在虚拟机中构建并将构建工件复制到容器中? Dockerfile 看起来像这样:

It there any way I can do this or should I resort to building in a virtual machine and copying the build artefacts into a container? The Dockerfile look like this:

FROM docker

RUN docker run --rm -v /opt/<myapp>:/opt/<myapp> <myapp> /build_and_install.sh /opt/<myapp>

# etc...

推荐答案

您的用例尚不清楚.也就是说,在许多情况下,这可以通过多阶段来完成构建.Docker推出了一个Java示例应用程序,其中包含阶段Dockerfile .

Your usecase is a little unclear. That said, in many cases this can be done with a multi-stage build. Docker has put out a sample Java application with a good example of a multi-stage Dockerfile.

这篇关于在docker build中运行docker命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆