Reputation: 452
I need to create a docker containing some code and a small flask server to expose some part of the code. But I struggle to make it working to my complex file architures. My files are organized as :
main_project
--sub_part_1
--repo_1
--some_code.py
--repo_2
--app.py
--Dockerfile
--repo_3
Pipfile.lock
--sub_part_2
--sub_part_3
--docker-compose.yml
I have to create a Dockerfile and a docker-compose.yml to run the app.py (flask app) and expose it on a given port
What I have now is
Dockerfile
FROM python:3.8-slim-buster as base
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1
ENV PYTHONUNBUFFERED 1
ENV FLASK_APP subpart_1/repo_2/app.py
ENV FLASK_RUN_HOST 0.0.0.0
RUN pip install pipenv
RUN apt-get update && apt-get install -y --no-install-recommends build-essential libpq-dev gcc musl-dev
COPY ./subpart_1/Pipfile /subpart_1/Pipfile
COPY ./subpart_1/Pipfile.lock /subpart_1/Pipfile.lock
WORKDIR /subpart_1
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy --ignore-pipfile --sequential
WORKDIR /
COPY ./subpart_1/repo_2 /subpart_1/repo_2/
COPY ./subpart_1/repo_1 /subpart_1/repo_1/
ENV PYTHONPATH /subpart_1/
WORKDIR /subpart_1
EXPOSE 5000
CMD ["flask", "run"]
and the docker-compose.yml
version: "3.9"
services:
web:
build: subpart_1/repo_2/
ports:
- "5000:5000"
But when I go in my main_project directory and run docker-compose up
I have
failed to compute cache key: failed to walk /var/lib/docker/tmp/buildkit-mount585608421/subpart_1: lstat /var/lib/docker/tmp/buildkit-mount585608421/subpart_1: no such file or directory
ERROR: Service 'web' failed to build : Build failed
Upvotes: 1
Views: 63
Reputation: 3168
It seems to me that's a path issue.
When setting subpart_1/repo_2/
in your docker-compose build file, the build will be done in this repertory. Docker will see the following files:
-app.py
-Dockerfile
thus the copy ./subpart_1/Pipfile /subpart_1/Pipfile
cannot work.
I think the easiest way is to put:
version: "3.9"
services:
web:
build:
context: .
dockerfile: sub_part_1/repo_2/Dockerfile
ports:
- "5000:5000"
Upvotes: 1