4

I have a Dockerfile

FROM python:3.7.12-slim-buster
FROM aaftio/face_recognition
RUN pip install redis
RUN pip3 install glob2

RUN pip install face_recognition
COPY ./worker.py /worker.py
COPY ./rediswq.py /rediswq.py

CMD  python3 worker.py

I build the image and run my image with docker run -it {image_id}, but I see errors from python app - It complains about f-strings syntax as it is supported since python 3.6 I address that it uses some older python.

I debugged and get python version it printed 1.19.0

The error:

      File "worker.py", line 14
    for filename in glob.iglob(f"/root/divisions/{division_number}/" + '**/*.*', recursive=True):
                                                                   ^
SyntaxError: invalid syntax

I debugged and executed whereis python3 and the output is

python3: /usr/bin/python3.5m-config /usr/bin/python3.5 /usr/bin/python3 /usr/bin/python3.5-config /usr/bin/python3.5m /usr/lib/python3 /usr/lib/python3.5 /etc/python3.5 /etc/python3 /usr/local/bin/python3.4m-config /usr/local/bin/python3.4m /usr/local/bin/python3.4 /usr/local/bin/python3 /usr/local/bin/python3.4-config /usr/local/lib/python3.4 /usr/local/lib/python3.5 /usr/include/python3.5 /usr/include/python3.5m /usr/share/python3
12
  • 1
    what is the actual error message? when testing with python 3.7.12 (via pyenv?), do you get the same errors? Commented Oct 7, 2021 at 19:43
  • No, I don't get any errors when I run my python app without Docker. When I dockerize my python app like above and try to run it complains about f-string syntax. I debugged it and at beginning of code I put simple f-string and it complained there. Commented Oct 7, 2021 at 19:45
  • 1
    To troubleshoot this, start a shell inside the docker image (I don't remember the exact syntax off the top of my head but you should be able to google it). Then run python3 -v in that shell. Does the output match what you expect? If you do python3 worker.py in the docker shell, does it give the same errors? Commented Oct 7, 2021 at 19:46
  • 1
    @Code-Apprentice I did and it shows Python 3.4.9 :/ Commented Oct 7, 2021 at 19:54
  • 3
    @memoricab The problem is in the way you have defined the dockerfile and tried to create a multi stage build. Your end docker container will always be based of the last docker container you have used in your Dockerfile for you it is aaftio/face_recognition which uses Python 3.4.9 and not python:3.7.12-slim-buster which uses Python 3.7.12. Reference for multi-stage docker builds - here Commented Oct 7, 2021 at 20:15

1 Answer 1

2

The error is in the way you have defined the Dockerfile

While creating a docker multi stage build, your final container will always be based off the last docker container you have referenced

So in your case it will be aaftio/face_recognition which uses Python 3.4.9 and not python:3.7.12-slim-buster which uses Python 3.7.12

Reference for docker multi stage build - here

You can try something like this

FROM aaftio/face_recognition as intermediate
RUN pip install face_recognition


FROM python:3.7.12-slim-buster

#Copy the python installed libraries from intermediate container
#COPY --from=intermediate face_recognition

RUN pip install redis
RUN pip3 install glob2
COPY ./worker.py /worker.py
COPY ./rediswq.py /rediswq.py

CMD  python3 worker.py
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.