制作centos base image for docker

来源:互联网 发布:淘宝正品代购可信吗 编辑:程序博客网 时间:2024/06/04 19:43

https://github.com/moby/moby/blob/master/contrib/mkimage-yum.sh

制作centos base image for docker



#!/usr/bin/env bash## Create a base CentOS Docker image.## This script is useful on systems with yum installed (e.g., building# a CentOS image on CentOS). See contrib/mkimage-rinse.sh for a way# to build CentOS images on other systems. set -e usage() {cat <<EOOPTS$(basename $0) [OPTIONS] <name>OPTIONS:-p "<packages>" The list of packages to install in the container.The default is blank.-g "<groups>" The groups of packages to install in the container.The default is "Core".-y <yumconf> The path to the yum config to install packages from. Thedefault is /etc/yum.conf for Centos/RHEL and /etc/dnf/dnf.conf for FedoraEOOPTSexit 1} # option defaultsyum_config=/etc/yum.confif [-f /etc/dnf/dnf.conf ] && command -v dnf &> /dev/null;thenyum_config=/etc/dnf/dnf.confalias yum=dnffiinstall_groups="Core"whilegetopts ":y:p:g:h" opt;docase$opt iny)yum_config=$OPTARG;;h)usage;;p)install_packages="$OPTARG";;g)install_groups="$OPTARG";;\?)echo"Invalid option: -$OPTARG"usage;;esacdoneshift$((OPTIND -1))name=$1 if [[-z $name ]];thenusagefi target=$(mktemp -d --tmpdir$(basename $0).XXXXXX) set -x mkdir -m 755 "$target"/devmknod -m 600 "$target"/dev/console c 5 1mknod -m 600 "$target"/dev/initctl pmknod -m 666 "$target"/dev/full c 1 7mknod -m 666 "$target"/dev/null c 1 3mknod -m 666 "$target"/dev/ptmx c 5 2mknod -m 666 "$target"/dev/random c 1 8mknod -m 666 "$target"/dev/tty c 5 0mknod -m 666 "$target"/dev/tty0 c 4 0mknod -m 666 "$target"/dev/urandom c 1 9mknod -m 666 "$target"/dev/zero c 1 5 # amazon linux yum will fail without vars setif [-d /etc/yum/vars ]; thenmkdir -p -m 755 "$target"/etc/yumcp -a /etc/yum/vars "$target"/etc/yum/fi if [[-n "$install_groups" ]];thenyum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \--setopt=group_package_types=mandatory -y groupinstall$install_groupsfi if [[-n "$install_packages" ]];thenyum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \--setopt=group_package_types=mandatory -y install$install_packagesfi yum -c "$yum_config" --installroot="$target" -y clean all cat > "$target"/etc/sysconfig/network<<EOFNETWORKING=yesHOSTNAME=localhost.localdomainEOF # effectively: febootstrap-minimize --keep-zoneinfo --keep-rpmdb --keep-services "$target".# localesrm -rf "$target"/usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive}# docs and man pagesrm -rf "$target"/usr/share/{man,doc,info,gnome/help}# cracklibrm -rf "$target"/usr/share/cracklib# i18nrm -rf "$target"/usr/share/i18n# yum cacherm -rf "$target"/var/cache/yummkdir -p --mode=0755"$target"/var/cache/yum# slnrm -rf "$target"/sbin/sln# ldconfigrm -rf "$target"/etc/ld.so.cache"$target"/var/cache/ldconfigmkdir -p --mode=0755"$target"/var/cache/ldconfig version=forfile in "$target"/etc/{redhat,system}-releasedoif [-r "$file" ];thenversion="$(sed's/^[^0-9\]*\([0-9.]\+\).*$/\1/'"$file")"breakfidone if [-z "$version" ];thenecho>&2 "warning: cannot autodetect OS version, using '$name' as tag"version=$namefi tar --numeric-owner -c -C"$target". | docker import - $name:$version docker run -i -t --rm$name:$version /bin/bash -c'echo success' rm -rf "$target"

原创粉丝点击