这是我的Dockerfile文件,用于类似于这个例子的无差异映像
FROM python:3.9-slim AS build-venv
RUN python3 -m venv /venv
# other installation steps go here
RUN /venv/bin/pip install --upgrade pip setuptools wheel
# installing from requirements.txt etc.
# Copy the virtualenv into a distroless image
FROM gcr.io/distroless/python3-debian11
COPY --from=build-venv /venv /venv
ENTRYPOINT ["/venv/bin/python3"]我正在尝试进入Python (安装了所有依赖项),但是docker run -it my-distroless给出了这个错误
docker: Error response from daemon: failed to create shim task:
OCI runtime create failed: runc create failed:
unable to start container process: exec: "/venv/bin/python3":
stat /venv/bin/python3: no such file or directory: unknown.但是,当用debian:11-slim替换基本图像时,一切都如预期的那样工作。
FROM debian:11-slim AS build
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev && \
python3 -m venv /venv
# the rest is the same是否只有“兼容”的基本图像是我应该在构建时使用的,或者是什么原因?
发布于 2022-10-22 03:57:24
您只是试图复制/venv目录,但这是行不通的。查看该目录的内容,例如:
root@52bdcc57abd8:/# python3 -m venv /venv
root@52bdcc57abd8:/# ls -l /venv/bin/
total 48
-rw-r--r-- 1 root root 8834 Oct 22 03:52 Activate.ps1
-rw-r--r-- 1 root root 1880 Oct 22 03:52 activate
-rw-r--r-- 1 root root 829 Oct 22 03:52 activate.csh
-rw-r--r-- 1 root root 1969 Oct 22 03:52 activate.fish
-rwxr-xr-x 1 root root 222 Oct 22 03:52 pip
-rwxr-xr-x 1 root root 222 Oct 22 03:52 pip3
-rwxr-xr-x 1 root root 222 Oct 22 03:52 pip3.9
lrwxrwxrwx 1 root root 7 Oct 22 03:51 python -> python3
lrwxrwxrwx 1 root root 22 Oct 22 03:51 python3 -> /usr/local/bin/python3
lrwxrwxrwx 1 root root 7 Oct 22 03:51 python3.9 -> python3正如您可以看到的那样,/venv/bin/python3实际上不是一个文件,它只是一个符号链接,指向用于创建虚拟环境的任何版本的Python。
您也不能仅仅复制二进制文件,因为您需要从/usr/local/lib/python3.9获得完整的运行时文件集,以及所有Python所需的共享库。
但是当用debian:11-slim取代基本图像时,一切都像预期的那样工作。
在本例中,您要安装的是兼容版本的Python...but,如果要这样做,最好还是坚持使用python:3.9-slim映像。
https://devops.stackexchange.com/questions/16762
复制相似问题