I am trying to splin up a ECR repo with some custom processing scripts for my data analysis:
this is my folder structure:
|-docker
| |--DockerFile
| |--requirement.txt
|-data_processes.py
|-preprocessing.py
This is the content I am writing in my dockerfile.
%%writefile docker/Dockerfile
FROM python:3.9.16-buster
WORKDIR /usr/src/processing_job #set working dir in container
COPY requirements.txt ../ #copy requirements in parent folder i.e. /usr/src/
RUN pip install --no-cache-dir -r ../requirements.txt
ENV PYTHONUNBUFFERED=TRUE
ADD preprocessing.py ./ #ADD files to /usr/src/processing_job since it current dir
ADD data_process.py ./ #ADD files to /usr/src/processing_job since it current dir
ENTRYPOINT ["python3", "preprocessing.py"]
my requirement file get’s installed properly but when it comes to ADD preprocessing.py ./ it fails with below message.
Step 6/8 : ADD preprocessing.py ./
ADD failed: file not found in build context or excluded by .dockerignore: stat preprocessing.py: file does not exist
How can I change my file structure or commands to add the files?
I want to add my preprocessing.py and data_processes.py files to be added to /usr/src/processing_job
3
Answers
You are building the container with your
docker/
directory as the build context. Only files in that directory are available to the build process. Thus, the.py
files in parent directory are not visible to the build process.You have to define build context so that it includes all files you need during the container build. This can be done, for example, by moving
Dockerfile
to same level where those.py
files currently are.You cannot include files data_processes.py and preprocessing.py because they are not in the same directory as Dockerfile.
The Dockerfile sees the files only on its own level and deeper. So you have to change your file structure to this:
The path is relative from where your Dockerfile is.
You have to add "../" before your .py files since they are in the parent directory.