1 回答
TA贡献1784条经验 获得超8个赞
希望你喜欢你的容器之旅,
关于你的错误信息,你可以检查一下: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 复制内容,而不仅仅是我们的主机文件系统)并添加 go path使用 dockerfile ENV 命令添加到 $PATH 环境变量,这是我的 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 image 是有限的,因为我无法安装我需要的东西,所以你可以用 centos:7 docker image 代替它。
解决方案 2:按照@Para 的建议尝试 yum install golang,您也可以直接使用 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。
- 1 回答
- 0 关注
- 331 浏览
添加回答
举报