CentOS7.x 支持的 gcc 和 g 版本太低,使用 CentOS 8.x 进行替换,但在实际操作的过程中,使用yum进行依赖更新,出现报错,写此文以记录。
代码语言:javascript复制FROM centos:8.4.2105
RUN set -eux;
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*;
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*;
yum clean all;
yum makecache;
yum -y install gcc
gcc-c
gdb
make
cmake;
yum clean all;
yum makecache
COPY [ "ninja", "/usr/local/bin" ]
FROM scratch
COPY --from=0 / /
ENV TZ="Asia/Shanghai"
LANG="zh_CN.UTF-8"
CMD [ "/bin/bash" ]
顺便把 openEuler 的 C 构建镜像的 Dockerfile 也写一下:
代码语言:javascript复制FROM openeuler:20.03
RUN set -eux;
yum -y install bc
gcc
gcc-c
gdb
make
cmake;
yum clean all;
yum makecache
FROM scratch
COPY --from=0 / /
ENV TZ="Asia/Shanghai"
LANG="zh_CN.UTF-8"
CMD [ "/bin/bash" ]
运行 ssh 服务的 Dockerfile:
代码语言:javascript复制FROM centos:8.4.2105
COPY [ "docker-entrypoint.sh", "/usr/local/bin" ]
RUN set -eux;
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*;
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*;
echo "root:develop" | chpasswd;
yum -y install gcc
gcc-c
gdb
make
cmake
openssh-server
rsync;
ssh-keygen -A;
yum clean all;
yum makecache;
chmod x /usr/local/bin/*;
rm -f /run/nologin;
rm -f /root/{anaconda-ks.cfg,anaconda-post.log,original-ks.cfg};
mkdir /var/run/sshd
FROM scratch
COPY --from=0 / /
ENV TZ="Asia/Shanghai"
LANG="zh_CN.UTF-8"
SSH_USERNAME="develop"
SSH_PASSWD="develop"
SSH_UID="1000"
SSH_GROUP="develop"
SSH_GID="1000"
ENTRYPOINT [ "docker-entrypoint.sh" ]
EXPOSE 22
CMD [ "/usr/sbin/sshd", "-D" ]
docker-entrypoint.sh 如下:
代码语言:javascript复制#!/bin/bash
set -eux
gcc -v
g -v
gdb -v
make -v
cmake -version
groupadd -g ${SSH_GID} ${SSH_GROUP}
useradd -d /home/${SSH_USERNAME} -m -c "Develop environment." -u ${SSH_UID} -g ${SSH_GID} -s /bin/bash ${SSH_USERNAME}
echo "${SSH_USERNAME}:${SSH_PASSWD}" | chpasswd
exec "$@"
容器启动命令:
代码语言:javascript复制docker run -d --restart always --hostname develop -e SSH_UID=`id -u` -e SSH_GID=`id -g` -e SSH_USERNAME=`whoami` -e SSH_PASSWD="dev123" -e SSH_GROUP=`id -g -n` --name develop -v ${HOME}/workspace:/home/`whoami` -p 2024:22 centos:sshd