0

I have a project structure as below

├───Project
│   ├───ServiceA
│   │    DockerFile
│   │    main.py
│   └───CommonFilesFolder
│        utils.py

and my DockerFile looks as below

FROM <base-image>

COPY . /app/
COPY ../CommonFilesFolder/ /app/CommonFilesFolder

ENV PYTHONPATH /app/

RUN pip install -U -r requirements.txt

WORKDIR /app/

CMD [ "python", "main.py"]

I understand that the line COPY . /app/ will copy all the contents of ServiceA Folder (The folder in which the DockerFile exists) to the container's app folder.

Similarly, I also want to copy the folder CommonFilesFolder into the /app, so I tried the line

COPY ../CommonFilesFolder/ /app/CommonFilesFolder

which is throwing me the error during the build

error: failed to solve: failed to compute cache key: "/CommonFilesFolder" not found: not found. Failed to build container

How exactly can I change the line COPY ../CommonFilesFolder/ /app/CommonFilesFolder to copy to the container.

Roman Pavelka
  • 3,736
  • 2
  • 11
  • 28
Vishnukk
  • 524
  • 2
  • 11
  • 27

1 Answers1

1

When building the container, you have to specify build context. I would say you use docker build .. That means your build context is current directory and you can't use anything outside of it.

Official documentation: https://docs.docker.com/engine/reference/commandline/build/#description

Check this answer how to resolve this: https://stackoverflow.com/a/51013639/12118546

Roman Pavelka
  • 3,736
  • 2
  • 11
  • 28