Docker:无法访问复制到某些图像的二进制文件 [英] Docker: Can't access binary copied to certain images

查看:75
本文介绍了Docker:无法访问复制到某些图像的二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 migrate 容器访问二进制文件 COPY 。当我 COPY python:3.7-alpine 时,它有效,但是当我 COPY debian:buster-slim 找不到。

I am trying to access a binary COPYed from the migrate container. When I COPY to python:3.7-alpine it works, but when I COPY to debian:buster-slim it can't be found.

复制的最小步骤:

1。创建Dockerfile.test

1.Create Dockerfile.test

FROM migrate/migrate:v4.6.2 AS migrate
FROM python:3.7-alpine
COPY --from=migrate /migrate /
CMD "/migrate"




  1. 生成并运行。可以。



docker build . -t migrate_test -f Dockerfile.test
docker run --name migrate_test migrate_test:latest



Usage: migrate OPTIONS COMMAND [arg...]
       migrate [ -version | -help ]




  1. 停止并移除容器



docker stop migrate_test;docker rm migrate_test;




  1. 在Dockerfile.test中更改映像



FROM migrate/migrate:v4.6.2 AS migrate
FROM debian:buster-slim
COPY --from=migrate /migrate /
CMD "/migrate"




  1. 构建并运行。



docker build . -t migrate_test -f Dockerfile.test
docker run --name migrate_test migrate_test:latest



/bin/sh: 1: /migrate: not found


推荐答案

看起来您的工作正常,但只是为了阐明可能会发现您问题的其他人的情况:

It looks like you have things working, but just to clarify the situation for other folks who might find your question:

问题在于, migrate / migrate:v4.6.2 建立在 Alpine 图片上,它使用 MUSL libc ,而大多数其他发行版都使用 glibc 。您会收到未找到消息,因为内核正在寻找路径嵌入到映像中的动态加载器,如我们使用 ldd 命令所看到的:

The issue is that the migrate/migrate:v4.6.2 is built on the Alpine image, which uses MUSL libc, whereas most other distributions use glibc. You're getting the "not found" message because the kernel is looking for the dynamic loader whose path is embedded in the image, as we see with the ldd command:

/ # ldd /migrate
        /lib/ld-musl-x86_64.so.1 (0x7f9e42ebd000)
        libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f9e42ebd000)

此二进制文件将在基于高山的映像上可用,而不是来自Debian,Ubuntu,Fedora,CentOS等的映像。一种选择是简单地复制Dockerfile中的必要加载程序:

This binary will be available on Alpine-based image, but not on images from Debian, Ubuntu, Fedora, CentOS, etc. One option is to simply copy over the necessary loader in your 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 命令分布。

Another solution would be to rebuild the migrate command for your target distribution.

这篇关于Docker:无法访问复制到某些图像的二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆