登录
首页 >  Golang >  Go问答

CentOS8容器无法加载“/lib64/ld-linux-x86-64.so.2”

来源:stackoverflow

时间:2024-02-08 08:36:25 298浏览 收藏

本篇文章向大家介绍《CentOS8容器无法加载“/lib64/ld-linux-x86-64.so.2”》,主要包括,具有一定的参考价值,需要的朋友可以参考一下。

问题内容

我在 M1 Mac 上,尝试在 CentOS 8 docker 容器内创建和构建 golang rpm 包

我在上面安装了 golang:

  1. wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
  2. sudo tar -C /usr/local -xf go1.13.4.linux-amd64.tar.gz
  3. export PATH=$PATH:/usr/local/go/bin 添加到 ~/.bash_profile
  4. source ~/.bash_profile

但是当我运行 go version 时,出现错误:

qemu-x86_64:无法打开“/lib64/ld-linux-x86-64.so.2”:没有这样的文件或目录

我在网上查了一下,但有类似错误的人似乎处于完全不同的情况,在这种情况下我无法复制。我该怎么做才能在这个 CentOS 容器上实际安装 golang?


正确答案


希望您享受容器之旅,

关于您的错误消息,您可以查看此:qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

但我也有一些建议可以帮助你: 由于我没有你的 dockerfile,我尝试使用这个:

from centos:8

run yum -y update && yum -y install wget
run wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
run sudo tar -c /usr/local -xf go1.13.4.linux-amd64.tar.gz
run echo "export path=$path:/usr/local/go/bin" >> ~/.bash_profile
run source ~/.bash_profile

让我们构建它:

❯ docker build -t so-go-version-centos8 .

问题是使用 centos8 docker 镜像,我无法更新或安装任何东西: (https://serverfault.com/questions/1091791/the-latest-centos8-docker-image-cannot-run-yum

❯ docker run -it centos:8
[root@d7c652e4ac65 /]# yum install wget
failed to set locale, defaulting to c.utf-8
centos linux 8 - appstream                                                                       0.0  b/s |   0  b     00:00
errors during downloading metadata for repository 'appstream':
  - curl error (6): couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=appstream&infra=container [could not resolve host: mirrorlist.centos.org]
error: failed to download metadata for repo 'appstream': cannot prepare internal mirrorlist: curl error (6): couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=appstream&infra=container [could not resolve host: mirrorlist.centos.org]

[root@d7c652e4ac65 /]# yum install golang
failed to set locale, defaulting to c.utf-8
centos linux 8 - appstream                                                                        95  b/s |  38  b     00:00
error: failed to download metadata for repo 'appstream': cannot prepare internal mirrorlist: no urls in mirrorlist

[root@d7c652e4ac65 /]# yum update
failed to set locale, defaulting to c.utf-8
centos linux 8 - appstream

所以我决定避免系统更新和安装 wget 并使用 dockerfile add 命令(add 和 copy 之间的区别是我们可以使用 add 直接从 url 复制内容,而不仅仅是我们的主机文件系统)并且使用 dockerfile env 命令将 go 路径添加到 $path env 变量,这是我的 df 的样子:

from centos:8

add https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz .
run tar -c /usr/local -xf go1.13.4.linux-amd64.tar.gz
env path=$path:/usr/local/go/bin

让我们构建它:

❯ docker build --no-cache -t so-go-version-centos8 -f dockerfile-centos8 .
[+] building 14.2s (8/8) finished
 => [internal] load build definition from dockerfile-centos8                                                                0.0s
 => => transferring dockerfile: 218b                                                                                        0.0s
 => [internal] load .dockerignore                                                                                           0.0s
 => => transferring context: 2b                                                                                             0.0s
 => [internal] load metadata for docker.io/library/centos:8                                                                 1.0s
 => cached https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz                                                             0.0s
 => cached [1/3] from docker.io/library/centos:8@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177    0.0s
 => [2/3] add https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz .                                                        2.2s
 => [3/3] run tar -c /usr/local -xf go1.13.4.linux-amd64.tar.gz                                                             7.5s
 => exporting to image                                                                                                      3.2s
 => => exporting layers                                                                                                     3.2s
 => => writing image sha256:26a8caea62889668498ca1d513b7db2c95b084a1d0020512e0c16dee365a880c                                0.0s
 => => naming to docker.io/library/so-go-version-centos8                                                                    0.0s
    /mnt/c/u/b/de/w/p/kind/manifests/stackoverflow/centos8-container-go-version ─────────────────────── 15s   02:21:46 
❯ docker run -it so-go-version-centos8
[root@78947ab8771a /]# go version
go version go1.13.4 linux/amd64
[root@78947ab8771a /]#

效果很好。

centos8 docker 镜像受到限制,因为我无法安装我需要的东西,所以你可以用 centos:7 docker 镜像替换它。

解决方案 2:尝试 yum install golang 正如@para建议的,你也可以直接用yum安装golang,但是“yum install -y golang”不起作用。所以我们必须手动安装它,就像我们所做的那样。

解决方案3:可以直接使用官方的golang docker镜像,即:

❯ docker run -it golang:buster
root@ed9f31e4a45a:/go# go version
go version go1.18.1 linux/amd64
root@ed9f31e4a45a:/go#

希望这对您有帮助,bguess。

终于介绍完啦!小伙伴们,这篇关于《CentOS8容器无法加载“/lib64/ld-linux-x86-64.so.2”》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>