无法在CentOS8容器中打开’/lib64/ld-linux-x86-64.so.2’。

huangapple go评论78阅读模式
英文:

Could not open '/lib64/ld-linux-x86-64.so.2' on CentOS8 container

问题

我正在一台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: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

我在网上查看了一些类似错误的解决方法,但是那些人的情况似乎与我的情况不同,我无法复制他们的解决方法。我应该怎么做才能在这个CentOS容器中正确安装Golang呢?

英文:

I am on a M1 Mac, trying to create and build a golang rpm package inside a CentOS 8 docker container.

I installed golang on it with:

  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. Adding export PATH=$PATH:/usr/local/go/bin to ~/.bash_profile
  4. source ~/.bash_profile

But when I run go versionI get the error:
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

I've taken a look online but the people with similar errors, seem to be in quite different scenarios that I can't replicate in this case. What can I do to actually install golang on this CentOS container?

答案1

得分: 2

希望你喜欢你的容器之旅,

关于你的错误信息,你可以查看这个链接:https://stackoverflow.com/questions/71040681/qemu-x86-64-could-not-open-lib64-ld-linux-x86-64-so-2-no-such-file-or-direc

但我也有一些建议,可能会对你有帮助:
由于我没有你的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环境变量中,这是我的dockerfile的样子:

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。

英文:

Hope you are enjoying you containers journey,

About your error message, you can check this: https://stackoverflow.com/questions/71040681/qemu-x86-64-could-not-open-lib64-ld-linux-x86-64-so-2-no-such-file-or-direc

But I also have some suggestions, that could help you:
Since i dont have your dockerfile, i tried with this one:

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

lets build it:

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

The problem is that with the centos8 docker images, i couldn't update or install anything:
(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

So I decided to avoid the system update and the installation of wget and use the dockerfile ADD command (the difference between ADD and COPY is that we can directly, with ADD, copy things from URLs instead of only our host filesystem) and adding go path to $PATH env variable with dockerfile ENV command, here is how my df looks like:

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

lets build it:

❯ 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 /]#

it worked well.

Centos8 docker image is then limited since i cant install what i need, So you can replace it by centos:7 docker image instead.

solution 2: try yum install golang
as @Para suggested, you could also directly install golang with yum, but "yum install -y golang" will not work. SO we have to install it manually, as we have done.

solution3: You can directly use an official golang docker image, i.e:

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

Hope this has helped you, bguess.

huangapple
  • 本文由 发表于 2022年4月24日 05:28:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/71983758.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定