简体   繁体   English

如何使用 wget 作为 Dockerfile 运行命令将文件下载到特定路径?

[英]How to download a file to a specific path using wget as a Dockerfile run command?

My app directory structure look like this:我的应用程序目录结构如下所示:

Root/
    app.py
    requirements.txt

    imageHelpers/
        helpers.py
        config.yml
        model.pth

Instead of copying my model.pth to the server, I want to download it from the web while building the container.我不想将我的model.pth复制到服务器,而是想在构建容器时从 web 下载它。 I want my model.pth to have the exact path as imageHelpers/model.pth .我希望我的model.pth的确切路径为imageHelpers/model.pth What should be the path for wget -O PATH_TO_MODEL URL ? wget -O PATH_TO_MODEL URL的路径应该是什么? Below is my Dockerfile下面是我的Dockerfile

FROM python:3.9

WORKDIR /fast_api_test

COPY ./requirements.txt /fast_api_test/requirements.txt

RUN pip3 install -r /fast_api_test/requirements.txt

COPY . .

RUN python -m pip install 'git+https://github.com/facebookresearch/detectron2.git' \
    && wget -q -O /imageHelpers/model.pth https://MY_URL/model.pth

EXPOSE 5000

CMD ["uvicorn",  "app:app", "--host", "0.0.0.0", "--port", "5000"]

Using AWS + Ubuntu if that's required.如果需要,请使用AWS + Ubuntu

when I run sudo docker build -t fast_api.当我运行sudo docker build -t fast_api. , it gives me error: ,它给了我错误:

/fast_api_test/imageHelpers/model.pth: No such file or directory

The command '/bin/sh -c pip3 install --upgrade -r /fast_api_test/requirements.txt     && python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'     && wget -q -O /fast_api_test/imageHelpers/model.pth https://MY_URL/model.pth' returned a non-zero code: 1


COPY (like ADD) tries to copy from OUTSIDE the image INTO the image. COPY(如 ADD)尝试从图像外部复制到图像中。

as the file is downloaded INSIDE the image already by wget, you need to use the commandline cp command由于文件已通过 wget 下载到图像内部,因此您需要使用命令行 cp 命令

try this:尝试这个:

RUN cp <downloaded_file> /fast_api_test
COPY . /fast_api_test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM