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:
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
- Adding
export PATH=$PATH:/usr/local/go/bin
to ~/.bash_profile source ~/.bash_profile
But when I run go version
I 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?
CodePudding user response:
Hope you are enjoying you containers journey,
About your error message, you can check this: qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
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.