dongshan8194 2019-04-14 11:40
浏览 392
已采纳

如何在dockerfile中复制时创建路径? [重复]

This question already has an answer here:

I'm try to copy some file in my php/dockerfile:

COPY ./supervisord.conf /etc/supervisor                 #work
COPY ../../config/supervisor/* /etc/supervisor/conf.d   #doesn't work

WORKDIR /home/wwwroot/

What should the correct path look like? This is my structure:

|config -> supervisor -> *
|
|docker -> php -> Dockerfile
|              -> supervisord.conf
|
</div>
  • 写回答

1条回答 默认 最新

  • dongpobo6009 2019-04-14 14:02
    关注

    The path must be inside the context of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.

    https://docs.docker.com/engine/reference/builder/

    dockerfile has the context of its own directory, and its unable to go above. this issue has a few workarounds, for instance:

    • run the docker build . command on the directory you want to be the context, with -f path/to/Dockerfile

    • another one - if you are using docker-compose, you can pass it a different context, for example, if youre structure goes like:

    .
    ├── docker-compose.yml
    └── app
       ├── Dockerfile
    

    then in your docker-compose file you can give it:

    services:
      app:
        build:
          context: .
          dockerfile: app/Dockerfile
    

    in this case, the context of the dockerfile will be 1 directory above. but thats seems a bit hacky to me. the correct approach is to put the dockerfile where the files you are trying to copy exists.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度