0

My tree is as follows:


project
│   
│   file001.txt
|   file002.txt  
|   file003.txt      
│
└───.devcontainer
   │   Dockerfile
   │   docker-compose.yml
   |   requirements.txt

And my goal is to create a container using the following Dockerfile and copy all the contents of the parent file under the newly created /app dir in the container.

My Dockerfile is as follows:

FROM python:3.9.10-alpine3.14
WORKDIR /app

RUN pip install --upgrade pip

RUN mkdir -p /app
RUN apk add build-base

COPY ./requirements.txt /tmp/


**# !!!! This part is not working !!!!!!
COPY ../ /app**


RUN pip3 install -r /tmp/requirements.txt 

ENTRYPOINT ["tail", "-f", "/dev/null"]

I haven't managed to find a proper solution. I tried add but the results are the same. Nothing happens.

Thanks in advance

Andreas Alamanos
  • 348
  • 3
  • 11
  • You need to move the Dockerfile up to the parent directory; the `docker build` directory name needs to be an ancestor of all of the files you contain in the image. [How to include files outside of Docker's build context?](https://stackoverflow.com/questions/27068596/how-to-include-files-outside-of-dockers-build-context) discusses this further. – David Maze Oct 06 '22 at 22:25

1 Answers1

0

When you build a container, you cannot include folders outside of the current build context.

The current context is almost always defined to be . (== ${PWD}) when you e.g.

docker build ... \
--file=./Dockerfile \
. # This little fella

A solution is to ensure that the build context includes (is a parent of) everything that you need to incorporate in your build but you need to revise your Dockerfile references:

cd {project} # Change to the {project} folder

docker build  ... \
--file=./.devcontainer/Dockerfile \
.
DazWilkin
  • 32,823
  • 5
  • 47
  • 88