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
CodePudding user response:
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