![](/img/trans.png)
[英]How can I plot an image with javascript, which I saved before in the docker workdir?
[英]How can I build a docker image with it parent folder as workdir?
这可能是一个愚蠢的问题,但我是 Docker 的新手,我对此感到很困惑。 我有一个包含许多子文件夹的项目,如下例所示:
project-folder:
folder_1:
code1.py
Dockerfile
requirements.txt
folder_2:
code2.py
Dockerfile
requirements.txt
folder_data:
file1
file2
file3
然后,我想这样做:
project-folder
中维护我的工作目录;folder_data
- 我知道我必须指定一个卷,我只是不知道如何在不将我的project-folder
保留为 workdir 的情况下执行此操作;project-folder
)传递给我的 code1.py注意:只有在每个子文件夹中创建图像时,我的图像才会成功创建,例如 Dockerfile:
FROM python:3.6-slim
COPY . /folder_1
WORKDIR /folder_1
RUN pip install -r requirements.txt
CMD ["python3", "code1.py", "$(pwd)"]
图像创建命令:
docker build -t image_folder1 .
我目前正在folder_1
的上下文中创建图像,因为我无法在project-folder
的上下文中正确创建图像
.
docker build
命令末尾的参数是上下文目录; 您COPY
到图像中的任何内容都必须在此子树中。 如果您需要在图像中包含其直接子树之外的内容,则需要使用祖先目录作为构建上下文,但您可以使用docker build -f
选项在子目录中命名文件。
cd project-folder
docker build -t image_folder1 -f folder_1/Dockerfile .
在 Dockerfile 中,由于您从父目录开始,您需要包含您COPY
的任何文件的相对路径; 但是,现在允许包含以前的同级目录。
FROM python:3.6-slim
WORKDIR /app
# Good practice to copy just dependencies first; this helps
# layer caching when you repeat `docker build`.
# COPY source path is relative to the `docker build` directory,
# which we've set up to be the parent of the application source.
COPY folder_1/requirements.txt .
RUN pip install -r requirements.txt
# Now copy in the rest of the application
COPY folder_1 .
# And also copy the shared data
COPY folder_data ./folder_data
# And have ordinary container startup metadata
CMD ["./code1.py"]
不要在这里使用卷。 Docker 具有从图像内容填充命名卷的诱人行为,但如果您重建旧卷内容将优先于更新的图像内容,这仅适用于本机 Docker 卷(不是主机目录绑定安装,根本不是在 Kubernetes 中)。 拥有一个包含应用程序需要运行的所有内容的独立映像比拥有需要从外部注入关键内容的部分映像更好的做法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.