docker 无法将文件从包复制到WORKDIR

koaltpgm  于 2022-12-11  发布在  Docker
关注(0)|答案(1)|浏览(182)

I tried to copy all files from some package into my WORKDIR in my Dockerfile
My Dockerfile look like this:

FROM python:3.8
WORKDIR /yahoo_finance_app
COPY requirements.txt /yahoo_finance_app/requirements.txt
COPY /manage_db/* /yahoo_finance_app/manage_db/
RUN pip3 install -r requirements.txt
COPY .. .

And I execute it with docker-compose which looks like this:

version: "3.8"
services:
  py-api-yahoo-finance:
    build: ./api-yahoo-finance/yahoo
    ports:
      - "5000:5000"
    container_name: api_yahoo_finance
    command: python manage.py runserver 0.0.0.0:5000

The file tree looks like this:

├── api_yahoo_finance
   ├── yahoo
      ├── Dockerfile

├── manage_db

I try to copy all the files from manage_db into my WORKDIR in my Dockerfile, but I got the following error:

=> ERROR [5/7] COPY /manage_db/* /yahoo_finance_app/manage_db/ 0.0s

[5/7] COPY /manage_db/* /yahoo_finance_app/manage_db/:
lstat /var/lib/docker/tmp/buildkit-mount563896323/manage_db: no such file or directory ERROR: Service 'py-api-yahoo-finance' failed to build : Build failed
And I take the relative path, so the folder is existing.
Thanks to all the helpers.

fhg3lkii

fhg3lkii1#

Dockerfiles are built in a variety of environments.
As a security and practical requirement Dockerfile commands can only access files that are in the context directory, either directly or in one of its children.
To keep Dockerfiles many levels deep, you can do this:

py-api-yahoo-finance:
    build:
      context: .
      file: ./api-yahoo-finance/yahoo/Dockerfile

and then all paths in the Dockerfile will be relative to the project root where the compose.yml is.

相关问题