$(pwd)-上一级 [英] $(pwd) - one level up

查看:480
本文介绍了$(pwd)-上一级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对bash / shell脚本世界还很陌生,我正在尝试做下面的事情,这可能很简单,但是我无法弄清楚该命令,如果有人可以帮助我,那会很好在这里,还向我指出了一些有关shell脚本主题的文档。

I'm pretty new to the bash/shell script world, I'm trying to do the below and it could be pretty simple but I wasn't able to figure out the command, would be great if someone could help me out here and also point me to some documentation wrt to shell script topics. Thank you in advance.

我的build.sh和Dockerfile驻留在名为.settings的文件夹下,并且该文件夹直接位于应用程序根目录下。现在当我引用诸如$(pwd)或COPY之类的东西时,在build.sh和Dockerfile中。 / apps /可能不起作用,因为我的build.sh和Dockerfile不在应用程序根目录下直接存在。

My build.sh and Dockerfile resides under a folder called .settings and this folder lives directly under the app root. Now inside my build.sh and Dockerfile when I refer something like $(pwd) or COPY . /apps/ it might not work since my build.sh and Dockerfile does not live directly under the app root.

在这种情况下,我可以在文件内部使用什么命令我在上面引用了。希望我说清楚。再一次,这可能非常简单,因为我是这个领域的新手,所以我觉得有点困难。

What command I can use in this scenario inside the files that I referenced above. Hope I made it clear. Once again this could be very simple since I'm a newbie in this arena I find it a little difficult.

inside build.sh, reference to $(pwd)

docker run \
-u root \
--rm \
-v $(pwd):/app \ ----> this $(pwd) references the application root, but if I 
move this build.sh inside a folder called .settings then the $(pwd) context 
would change and I still want to refer it to the root.
<MYIMAGE NAME FROM LOCAL REPO>


推荐答案

docker的最后一个参数build ,通常类似于 docker build。是docker中的构建上下文。该目录被发送到运行构建的服务器,并且所有 COPY ADD 命令都使用此上下文执行。这些命令无法在客户端上运行,而docker是客户端/服务器应用程序,因此,在此上下文中不存在的任何东西都不存在,无法用于构建映像。

The last arg to docker build, often something like docker build . is the build context in docker. This directory is sent to the server where the build runs and all COPY and ADD commands are performed using this context. These commands do not run on the client, and docker is a client/server application, so anything not in that context simply doesn't exist for the purpose of building an image.

因此在上面的示例中, docker build。当前目录是构建上下文,如果它在内部运行时正在运行。 目录,只有那些文件是构建上下文的一部分。因此,您的 build.sh 脚本需要传递一个不同的目录,并引用 Dockerfile 在该内部版本的位置。上下文。看起来像这样:

So in the above example, docker build . the current directory is the build context and if that's run while you're inside of the .settings directory, only those files are part of the build context. Therefore your build.sh script needs to pass a different directory, and also reference where the Dockerfile is inside of that build context. That would look like:

docker build -f .settings/Dockerfile ..

执行此操作时,所有 COPY ADD 命令现在将与父目录相关,因此您可能需要调整 Dockerfile 进行补偿。

When you do this, all of the COPY and ADD commands will now be relevant to parent directory, so you may need to adjust your Dockerfile to compensate.

对于您的 $(pwd)参考,您可以 cd .. ,然后再运行 docker run 命令,或将命令更新为以下样子:

For your $(pwd) reference, you can either cd .. before running your docker run command or update the command to look like:

docker run \
  -u root \
  --rm \
  -v $(pwd)/..:/app \
  <your image>

这篇关于$(pwd)-上一级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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