我正在尝试基于centos7
构建一个泊坞窗图像
FROM centos:centos7
RUN yum -y update
RUN yum -y install gcc
RUN gcc --version
安装的gcc
是4.8:
步
4/4 : RUN gcc --version
---> Running in 70b9aa4a1f67
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
我该如何安装gcc7?我试过devtools-7,它不起作用:
FROM centos:centos7
RUN yum -y update
RUN yum -y install scl-utils
RUN yum -y install devtoolset-7-gcc
RUN scl enable devtoolset-7 bash
RUN gcc --version
我有:
Step 4/6 : RUN yum -y install devtoolset-7-gcc
---> Running in 85b49f411d4c
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirror.imt-systems.com
* extras: mirror.23media.com
* updates: ftp.plusline.net
No package devtoolset-7-gcc available.
Error: Nothing to do
The command '/bin/sh -c yum -y install devtoolset-7-gcc' returned a non-zero code: 1
FROM centos:centos7
RUN yum update -y
RUN yum groupinstall "Development Tools" -y
RUN yum install wget -y
RUN curl -O https://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
RUN tar xzf gcc-7.3.0.tar.gz
RUN cd gcc-7.3.0
RUN ./contrib/download_prerequisites
RUN cd ..
RUN mkdir gcc-build
RUN cd gcc-build
RUN ../gcc-7.3.0/configure \
--enable-shared \
--enable-threads=posix \
--enable-__cxa_atexit \
--enable-clocale=gnu \
--disable-multilib \
--enable-languages=all
RUN make
# (Go make a cup of ice tea :)
RUN make install
为了节省构建时间,您可以使用“docker commit”从正在运行的docker创建一个新的docker,或者将/ usr / local保存到tar文件中,并在任何其他新的centos7 docker上打开它。
显然,您当前的存储库配置中不存在devtoolset-7-gcc。尝试添加一个拥有它的回购,或尝试yum -y install centos-release-scl
而不是yum -y install scl-utils
。
在这里找到它:http://blog.stevedoria.net/20180214/how-to-install-gcc-7-on-centos-7
玩得开心!
编辑:
经过一些更多的研究,似乎确实安装了gcc 7,但scl enable实际上是打开一个包含你的GCC 7的新bash。如果你真的需要GCC 7作为默认的gcc,你可以从源代码编译它(但是它需要一个loooong时间),或者您可以使用dockerfile中的SHELL命令在shell之间交替。这是我的docker文件:
FROM centos:centos7
RUN yum -y update
RUN yum -y install centos-release-scl
RUN yum -y install devtoolset-7-gcc*
SHELL [ "/usr/bin/scl", "enable", "devtoolset-7"]
RUN gcc --version
和RUN gcc --version
的输出
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
在使用devtoolset时,shell之间的交替似乎是预期的方法,因为它允许您在需要时快速切换版本。我希望这有帮助