当前位置: 首页 > 知识库问答 >
问题:

linux - docker 文件卷,如何把本地的文件,映射到容器的某个文件夹中?

燕航
2023-05-25
version: "3"
services:
  nginx:
    container_name: nginx
    image: nginx:latest
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./fastapi_example.conf:/etc/nginx/conf.d/
    ports:
      - 80:80

fastapi_example.conf 是我的本地文件

我想放到容器的 /etc/nginx/conf.d/ 路径下,但是报错了

╰─➤  docker-compose up -d      
Recreating nginx ... error

ERROR: for nginx  Cannot start service nginx: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/home/pon/opt/docker-compose-public/nginx/fastapi_example.conf" to rootfs at "/etc/nginx/conf.d": mount /home/pon/opt/docker-compose-public/nginx/fastapi_example.conf:/etc/nginx/conf.d (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

ERROR: for nginx  Cannot start service nginx: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/home/pon/opt/docker-compose-public/nginx/fastapi_example.conf" to rootfs at "/etc/nginx/conf.d": mount /home/pon/opt/docker-compose-public/nginx/fastapi_example.conf:/etc/nginx/conf.d (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
ERROR: Encountered errors while bringing up the project.

共有2个答案

杭英杰
2023-05-25

用这种方式:

...
volumes:
    - type: bind
      source: ./fastapi_example.conf
      target: /etc/nginx/conf.d/fastapi_example.conf
姜献
2023-05-25

我们挂载的时候都是具体到文件。比如用本地的global.js文件替换容器里面的global.js文件

 volumes:
    - /opt/devops/config/web/global.js:/usr/share/nginx/html/static/global.js
 类似资料:
  • 我只需要将构建文件夹中的文件(和子文件夹)复制到..html中。 是我遗漏了什么还是我必须一个一个地复制每个文件?

  • 问题内容: 尝试将文件从一个文件夹复制到现有容器文件夹时,我是否丢失了某些内容: 文件 我想将build(host)文件夹中的文件复制到容器中的html: 要清楚;我需要从主机复制到容器。 但是它将复制整个构建文件夹并将其复制到..html / build 我只需要将build文件夹中的文件(和子文件夹)复制到..html中。 我是否缺少某些内容,还是必须一个一个地复制每个文件? 问题答案: 这是

  • 问题内容: 我在将包含该文件夹中文件的文件夹复制到另一个文件夹时遇到一些问题。Command 不会复制文件夹中的文件。 问题答案: 您正在寻找的选项是。 如果不存在,将创建它。 意味着。您也可以使用,因为它不区分大小写。 请注意根据@ muni764的注释添加尾随的细微差别。

  • 本文向大家介绍linux把一个文件的内容复制到另一个文件的末尾,包括了linux把一个文件的内容复制到另一个文件的末尾的使用技巧和注意事项,需要的朋友参考一下 问题描述: 比如11的文件内容是: hello 22的文件内容是: world 将22的文件内容复制到11文件的末尾,11文件的效果就是: hello world 解决办法: cat 22 >> 11 >>的意思是追加的意思 > 的意思是重

  • 我有一个场景,比如我必须将几个配置文件复制到存在于docker容器中的tomcat webapps文件夹中。这是我使用的dockerfile 一旦我们运行docker,它实际上会执行以下操作 它实际上将app.war复制到tomcat webapps文件夹,并提取到名为“app”的文件夹 Docker将尝试启动tomcat服务器。 我想将配置文件复制到提取的war文件中,该文件位于tomcat w

  • 我也在尝试用Python创建一个脚本来读取文本文件。在文本文件的每一行上,都有一个文件名。我希望脚本在文本文件的每一行中循环,并将带有文件名的文件从循环的当前行、从源文件夹移动到特定的目标。 希望这段代码能更准确地说明我在做什么: 我想把文件的内容和特定的文件名放到一个数组中,但是我有62700个可能的文件名,所以我想如果它只是在循环到每一行时移动文件,那么它会更有效率吗? 我还想到了使用迭代器(