Docker如何通过相对路径作为参数 [英] Docker how to pass a relative path as an argument

查看:489
本文介绍了Docker如何通过相对路径作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行以下命令:

docker run docker-mup deploy --config .deploy/mup.js

其中 docker-mup 是图片和 deploy -config .deploy / mup.js 是参数

where docker-mup is the name the image, and deploy, --config, .deploy/mup.js are arguments

我的问题:如何挂载这样的卷,例如 .deploy / mup.js 被理解为运行 docker run 命令的主机上的相对路径?

My question: how to mount a volume such that .deploy/mup.js is understood as the relative path on the host from where the docker run command is run?

我尝试了不同的方法使用 VOLUME ,但是VOLUME似乎恰恰相反:它将容器目录公开给主机。

I tried different things with VOLUME but it seems that VOLUME does the contrary: it exposes a container directory to the host.

我可以不要使用-v,因为此容器将用作CI / CD管道中的构建步骤,据我了解,它只是按原样运行。

I can't use -v because this container will be used as a build step in a CI/CD pipeline and as I understand it, it is just run as is.

推荐答案


我不能使用-v,因为此容器将用作CI / CD管道中的构建步骤,据我所知,它只是以是。

I can't use -v because this container will be used as a build step in a CI/CD pipeline and as I understand it, it is just run as is.

使用 -v 公开当前目录是使该的唯一方法容器中的.deploy / mup.js 文件,除非您使用<$ c $中的 COPY 指令将其烘焙到图像本身中c> Dockerfile 。

Using -v to expose your current directory is the only way to make that .deploy/mup.js file inside your container, unless you are baking it into the image itself using a COPY directive in your Dockerfile.

使用 -v 选项映射主机目录可能看起来像这样:

Using the -v option to map a host directory might look something like this:

docker run -v $PWD/.deploy:/data/.deploy -w /data docker-mup deploy --config .deploy/mup.js

这将映射 $ PWD / .deploy 目录到容器中的 /data/.deploy 上,将当前工作目录设置为 / data ,然后运行 deploy --config .deploy / mup.js

This would map the $PWD/.deploy directory onto /data/.deploy in your container, set the current working directory to /data, and then run deploy --config .deploy/mup.js.

这篇关于Docker如何通过相对路径作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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