我正在尝试构建一个基于centos7的docker镜像
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发布于 2019-04-29 22:17:49
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上打开它。
发布于 2019-07-18 06:11:46
Dockerfile中的以下命令对我有效:
RUN yum install -y centos-release-scl
RUN yum install -y devtoolset-7-gcc-*
RUN echo "source scl_source enable devtoolset-7" >> /etc/bashrc
RUN source /etc/bashrc发布于 2019-04-29 19:29:48
显然,您当前的存储库配置中不存在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实际上正在打开一个新的bash,其中将包含您的GCC 7。如果您确实需要使用GCC 7作为默认的gcc,您可以从源代码编译它(但这需要很长的时间),或者您可以使用您的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.在shell之间进行更改似乎是使用devtoolset时的预期方式,因为它允许您在需要时在版本之间快速切换。我希望这对你有所帮助
https://stackoverflow.com/questions/55901985
复制相似问题