ADD failed : No such file/Directory while building docker image

前端 未结 3 1887
遥遥无期
遥遥无期 2020-12-16 12:16

I have below Dockerfile:

FROM python:3

RUN mkdir -p /test/code/
RUN mkdir -p /test/logs/
RUN mkdir -p /test/configs/

ADD test.py /test/code/
ADD test_outpu         


        
相关标签:
3条回答
  • 2020-12-16 12:27

    This doesn't work because test_input.txt is not in the docker build context.

    When you execute the command sudo docker build -t myimage . the last '.' indicates the build context. What docker does is that it uploads the context to the docker deamon to build the image. In your case the context does not contain test_input.txt, thus it is not uploaded and docker can't find the file/

    There are two ways to solve this:

    1. Inside test directory run the command sudo docker build -t myimage -f code/Dockerfile .. In this case the context includes all the test directory. Then modify the Dockerfile to account for this change:

    FROM python:3
    ...    
    ADD code/test.py /test/code/
    ADD code/test_output.txt /test/code/
    ADD config/test_input.txt /test/configs/
    ADD logs/logfile.log /test/logs/
    
    1. The second option is to simply move the Dockerfile to the test folder and modify it as above. In that case the command sudo docker build -t myimage . should work.
    0 讨论(0)
  • 2020-12-16 12:27

    Also make sure to not add in the .dockerignore file a file or folder that is needed during the image building process.

    0 讨论(0)
  • 2020-12-16 12:28

    Because test_input.txt is in another directory,either put this file in place where dockerfile is there similar to test_output.txt or give full path in ADD command

    ADD ../configs/test_input.txt /test/configs/
    

    Even for logfile.log this u will get error , so change to

    ADD ../logs/logfile.log /test/logs/
    
    0 讨论(0)
提交回复
热议问题