无法在 CentOS8 容器上打开“/lib64/ld-linux-x86-64.so.2”
Could not open '/lib64/ld-linux-x86-64.so.2' on CentOS8 container
我在 M1 Mac 上,试图在 [=25] 中创建和构建 golang rpm 包 =]CentOS 8docker容器。
我在上面安装了 golang:
wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
sudo tar -C /usr/local -xf go1.13.4.linux-amd64.tar.gz
- 添加
export PATH=$PATH:/usr/local/go/bin
到 ~/.bash_profile
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
但我也有一些建议,可以帮助你:
因为我没有你的 docker 文件,所以我尝试了这个:
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/Whosebug/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 image 是有限的,因为我无法安装我需要的东西,所以你可以用 centos:7 docker image 代替它。
解决方案 2:尝试 yum 安装 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。
我在 M1 Mac 上,试图在 [=25] 中创建和构建 golang rpm 包 =]CentOS 8docker容器。
我在上面安装了 golang:
wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
sudo tar -C /usr/local -xf go1.13.4.linux-amd64.tar.gz
- 添加
export PATH=$PATH:/usr/local/go/bin
到 ~/.bash_profile 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
但我也有一些建议,可以帮助你: 因为我没有你的 docker 文件,所以我尝试了这个:
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/Whosebug/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 image 是有限的,因为我无法安装我需要的东西,所以你可以用 centos:7 docker image 代替它。
解决方案 2:尝试 yum 安装 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。