构建镜像
-
编写Dockerfile
FROM centos:6.9 ARG USERNAME=builder ARG USER_UID=1000 ARG USER_GID=$USER_UID RUN sed -e "s|^mirrorlist=|#mirrorlist=|g" \ -e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/6.9|g" \ -i.bak /etc/yum.repos.d/CentOS-*.repo \ && yum makecache \ && yum install -y sudo centos-release-scl* \ && sed -e "s|http://mirror.centos.org/centos/6|https://mirrors.tuna.tsinghua.edu.cn/centos-vault/6.9|g" -i.bak /etc/yum.repos.d/CentOS-SCL*.repo \ && yum install -y devtoolset-4-gcc devtoolset-4-gcc-c++ devtoolset-4-gdb \ && yum install -y devtoolset-7-gcc devtoolset-7-gcc-c++ devtoolset-7-gdb \ && yum install -y wget \ && wget https://github.com/Kitware/CMake/releases/download/v3.24.0/cmake-3.24.0-linux-x86_64.tar.gz \ && tar zxf cmake-3.24.0-linux-x86_64.tar.gz \ && mv cmake-3.24.0-linux-x86_64 /usr/local/cmake-3.24.0 \ && ln -sf /usr/local/cmake-3.24.0/bin/* /usr/local/bin \ && rm -f cmake-3.24.0-linux-x86_64.tar.gz \ && yum clean all \ && echo "source /opt/rh/devtoolset-7/enable" >> /etc/bashrc \ # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user. && groupadd --gid $USER_GID $USERNAME \ && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME -G $USERNAME -d /build \ # [Optional] Add sudo support for non-root user && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME && yum install -y libXext-devel libxcb-devel libX11-xcb-devel libX11-devel libXi-devel libXrender-devel freetype-devel fontconfig-devel dbus-devel glib2-devel gthread-devel
-
编译
docker build -t centos6_gcc .
-
在项目路径进入容器
docker run -it --rm \ --name dev_builder \ -u builder \ -v $PWD:/workspace \ -w /workspace \ centos6_gcc bash
-
提交到 docker hub
docker tag centos6_gcc igwkang/centos6_gcc docker push igwkang/centos6_gcc
提交完成后可以直接拉取
拉取镜像
docker pull igwkang/centos6_gcc:latest
docker run -it --rm \
--name dev_builder \
-u builder \
-v $PWD:/workspace \
-w /workspace \
igwkang/centos6_gcc bash