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

Viewed 38

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. I want my model.pth to have the exact path as imageHelpers/model.pth. What should be the path for wget -O PATH_TO_MODEL URL? Below is my 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.

when I run 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


1 Answers

COPY (like ADD) tries to copy from OUTSIDE the image INTO the image.

as the file is downloaded INSIDE the image already by wget, you need to use the commandline cp command

try this:

RUN cp <downloaded_file> /fast_api_test
COPY . /fast_api_test
Related