I created a slim docker file for my app:
FROM python:3.7-slim-stretch AS build
RUN python3 -m venv /venv
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git && \
apt-get install -y build-essential && \
rm -rf /var/cache/apt/* /var/lib/apt/lists/*
ADD ./requirements.txt /project/
RUN /venv/bin/pip install -r /project/requirements.txt
ADD . /project
RUN /venv/bin/pip install /project
WORKDIR /project
FROM python:3.7-slim-stretch AS production
COPY --from=build /venv /venv
CMD ["/venv/bin/python3","-m", "myapp"]
The docker is building and working. The running python executable is copied from the build image. (Verified, if I remove "/venv/bin" it won't run). However, to save some space I want to change my production base docker to:
FROM debian:stretch-slim
But then I'm getting an error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"/venv/bin/python3\": stat /venv/bin/python3: no such file or directory": unknown.
Now, I don't understand this error. I can see the python executable is there, why he wouldn't run? Whats in the base python docker image allow it to run?
Go in your venv
in your container and ls -l
the bin directory.
lrwxrwxrwx 1 root root 21 Dec 4 17:28 python -> /usr/local/bin/python
Yes python
is there but it is a symlink to a file which does not exists.
You can go around this first problem by using RUN python3 -m venv --copies /venv
in your Dockerfile.
But you will then hit the following error message:
error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory
So you will finally need to install the exact same version of python in your image as the one available at build time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.