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.

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

报告相同问题?