这可能是个愚蠢的问题,但我是码头的新手,我正努力解决这个问题。我有一个带有许多子文件夹的项目,如下所示:
project-folder:
folder_1:
code1.py
Dockerfile
requirements.txt
folder_2:
code2.py
Dockerfile
requirements.txt
folder_data:
file1
file2
file3然后,我想这样做:
containers;
project-folder中维护工作日志,我应该能够访问folder_data --我知道我必须指定一个卷,我只是不知道如何做到这一点,而不把project-folder作为workdir;project-folder)传递给我的code1.pyG 212
注意:只有在每个子文件夹中创建映像时,我的映像才会成功创建,比如这个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上下文中正确地创建图像。
发布于 2021-02-28 00:44:38
.命令末尾的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中,没有主机目录绑定挂载,根本不起作用)。最好有一个包含应用程序需要运行的所有内容的独立映像,而不是需要从外部注入关键内容的部分映像。
https://stackoverflow.com/questions/66404692
复制相似问题