docker使用----How to include files outside of Docker's build context?

怼烎@ 2022-04-23 00:00 266阅读 0赞

目标:在于解决ADD/COPY当前Dockerfile所在目录之外的目录下的文件

文件目录结构如下:

  1. project
  2. ├── dockerfile
  3. ├── docker-compose.yml
  4. └── Dockerfile
  5. └── test
  6. └── 1.txt

常用错误思路:

  1. Dockerfile:
  2. FROM ubuntu:latest
  3. COPY ../test/1.txt /
  4. RUN echo $whl
  • 提示:COPY failed: Forbidden path outside the build context: …/test/1.txt ()

正确处理方法

1.修改Dockerfile

  1. FROM ubuntu:latest
  2. # COPY ../test/1.txt /
  3. COPY test/1.txt /
  4. RUN echo $whl

2.在最外层目录下使用下面命令build

  1. docker build -f dockerfile/Dockerfile .

3.也可以配置docker-compose.yml使用

  1. docker-compose.yml
  2. version: '3'
  3. services:
  4. web:
  5. build:
  6. context: ../
  7. dockerfile: dockerfile/Dockerfile
  8. expose:
  9. - "8000"
  • docker-compose.yml所在目录使用命令:

    docker-compose up web

发表评论

表情:
评论列表 (有 0 条评论,266人围观)

还没有评论,来说两句吧...

相关阅读