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 build no No such file or directory

From the directory I am trying to run the command

sudo docker-compose -f project/docker/docker-compose.yml up

tree

This is the error I get

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

    ubuntu@ip-172-31-90-166:~/tp3-securite-applicative$ sudo docker-compose -f project/docker/docker-compose.yml up
    Recreating docker_api-service-track-1_1 ... done
    Attaching to docker_api-service-track-1_1
    api-service-track-1_1  | python path is:
    api-service-track-1_1  | //project/
    api-service-track-1_1  | running the following python program
    api-service-track-1_1  | ./project/codeAPI/API.py ./project/codeAPI/front.py
    api-service-track-1_1  | python3: can't open file '//./project/codeAPI/API.py': [Errno 2] No such file or directory
    api-service-track-1_1  | python3: can't open file '//./project/codeAPI/front.py': [Errno 2] No such file or directory

This is my Dockerfile

FROM python:3
ADD ./run.sh /
ADD ./requirements.txt /
RUN pip3 install -r ./requirements.txt
CMD ["./run.sh", "./project/codeAPI/API.py", "./project/codeAPI/front.py"]

This is my docker-compose.yml

version: '3'

services:
  api-service-track-1:
    build:
      context: ../../
      dockerfile: ./project/docker/Dockerfile
    image: img_track1
    volumes:
      - ./:/mnt/app
    ports:
      - 5551:5551
    tty: true

I define my python path in my run.sh

#!/bin/bash

export PYTHONPATH=$PWD/project/
echo python path is:
echo $PYTHONPATH

echo running the following python program
echo $@
python3 "$1"
python3 "$2"

requirements.txt contains a bunch of imports.

I tried multiple ways to adapt my python path by modifying my run.sh and my Dockerfile but I am unable to find my front.py and API.py. Do I not understand the concept of path or am missing something obvious?

edit 1 after Saikiran Rudra correction:

ubuntu@ip-172-31-90-166:~/tp3-securite-applicative$ sudo docker-compose -f project/docker/docker-compose.yml up
Creating network "docker_default" with the default driver
Creating docker_api-service-track-1_1 ... done
Attaching to docker_api-service-track-1_1
api-service-track-1_1  | python path is:
api-service-track-1_1  | //project/
api-service-track-1_1  | running the following python program
api-service-track-1_1  | ./project/codeAPI/API.py ./project/codeAPI/front.py
api-service-track-1_1  | /usr/local/bin/python3: can't find '__main__' module in '//./project/codeAPI/API.py'
api-service-track-1_1  | /usr/local/bin/python3: can't find '__main__' module in '//./project/codeAPI/front.py'

>Solution :

I faced similar problem try this it worked for me

In docker-compose.yml in volumes section add this lines

volumes:
      - ./:/mnt/app
      - /project/codeAPI/API.py
      - /project/codeAPI/front.py
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