我正在尝试从COPY
容器访问二进制文件migrate
。当我COPY
到python:3.7-alpine
时可以工作,但是当我COPY
到debian:buster-slim
时找不到。
复制的最少步骤:
1。创建Dockerfile.test
FROM migrate/migrate:v4.6.2 AS migrate
FROM python:3.7-alpine
COPY --from=migrate /migrate /
CMD "/migrate"
docker build . -t migrate_test -f Dockerfile.test
docker run --name migrate_test migrate_test:latest
Usage: migrate OPTIONS COMMAND [arg...]
migrate [ -version | -help ]
docker stop migrate_test;docker rm migrate_test;
FROM migrate/migrate:v4.6.2 AS migrate
FROM debian:buster-slim
COPY --from=migrate /migrate /
CMD "/migrate"
docker build . -t migrate_test -f Dockerfile.test
docker run --name migrate_test migrate_test:latest
/bin/sh: 1: /migrate: not found
答案 0 :(得分:1)
您似乎有事可做,但只是为可能会发现您问题的其他人澄清情况:
问题是migrate/migrate:v4.6.2
建立在Alpine图像的基础上,该图像使用MUSL libc,而其他大多数发行版都使用glibc。之所以收到“未找到”消息,是因为内核正在寻找路径已嵌入到映像中的动态加载器,如我们在ldd
命令中看到的那样:
/ # ldd /migrate
/lib/ld-musl-x86_64.so.1 (0x7f9e42ebd000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f9e42ebd000)
此二进制文件将在基于Alpine的映像上可用,但在来自Debian,Ubuntu,Fedora,CentOS等的映像上不可用。一种选择是简单地复制Dockerfile中所需的加载程序:
FROM migrate/migrate:v4.6.2 AS migrate
FROM debian:buster-slim
COPY --from=migrate /migrate /
COPY --from=migrate /lib/ld-musl-x86_64.so.1 /lib/ld-musl-x86_64.so.1
CMD "/migrate"
另一种解决方案是为目标分发版本重建migrate
命令。