Passing file as argument to Docker container

后端 未结 5 786
名媛妹妹
名媛妹妹 2020-12-29 18:23

A very simple python program, suppose current directory is /PYTHON, I want to pass file.txt as argument to python script boot.py, here is my Dockerfile

FRO         


        
5条回答
  •  一个人的身影
    2020-12-29 18:53

    It won't work that way. Like you said, file1.txt is not in the container.

    The work around is to use Docker volumes to inject files from your host machine to the container when running it.

    Something like this :

    docker run -v /local/path/to/file1.txt:/container/path/to/file1.txt -t boot:latest python boot.py file1.txt
    

    Then /local/path/to/file1.txt would be the path on your host machine which will override /container/path/to/file1.txt on the container.

提交回复
热议问题