I'm using the following Dockerfile:
FROM python:3.9
ENV PYTHONUNBUFFERED True
ENV PYTHONPATH /app
WORKDIR /app/services/big_box
RUN pip install "poetry==1.1.8"
COPY ./services/big_box/pyproject.toml \
./services/big_box/poetry.lock \
./
COPY ./lib ../../lib
RUN poetry config virtualenvs.create false && \
poetry install --no-dev
COPY ./services/big_box/src ./src
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 'src.app:create_app()'
My directory structure is like: Directory Structure
To build the docker image I run the following command from inside backend-python:
docker build -t big_box ./services/big_box
But I get the following errors: Error
I've checked the locations of all directories multiple times but do not know why I'm getting this error. I'm using Mac, VS code, Python, Poetry and Docker.
CodePudding user response:
Your problem is the docker build context.
Since you do not specify any different context, docker runs with the default: The directory holding your dockerfile is the build context. Everything in the context will be zipped and sent to the docker daemon which tries to build the image. If you try to reference files outside of that context the instruction is bound to fail, and that is what you perceive.
So what you need to do is to specify the current directory as root context, but then you need to tell docker that the Dockerfile is not in the root directory:
docker build -t big_box -f /services/big_box/Dockerfile .