Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Docker creation with web service in complex architecture

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading