Bulk Install Docker 1.12 and add Docker Macvlan network support with Ansible CENTOS7 system
Ansible directory Structure
.├── hosts├── roles│ └── docker_client│ ├── defaults│ ├── files│ ├── handlers│ ├── meta│ ├── tasks│ │ └── main.yml # ansible Install docker script │ ├── templates│ │ └── docker.repo # docker Latest Yum Source │ └── vars├── site.retry└── site.yml # ansible Master Control Script
SITE.YML file Content Description-Hosts:all # All clients user:root #root用户执行 Vars:network_card:eth0 # Add Macvlan to participate in the local NIC name modified according to the actual situation SUBNET:192.168.0.0/21 # network Segment with host one segment gateway:192.168.0.210 # gateway Docker using Netname:eth0_1 #docker macvlan nic name ro Les:-Docker_client # Docker installation Project
Main.yml File Content Description
- stat: path=/usr/bin/docker # determine if Docker register: docker_path_ is installed register- name: yum old docker yum: name=docker* state=removed # Uninstall docker when: docker_path_register.stat.exists == true # Already installed uninstall already installed docker- name: cp docker.repo client template: src= docker.repo dest=/etc/yum.repos.d/docker.repo # upload the latest docker yum source to the client- name: yum install docker-engine # installation Docker yum: name=docker-engine state=present - name: enabled service docker.service #打开docker Services boot up service: name=docker.service enabled=yes- name: start service docker.service service: name=docker state=started #启动docker Service- name : chmod +x /etc/rc.d/rc.local shell: chmod +x /etc/rc.d/rc.local #设置rc .local Execute Permissions- Lineinfile: dest=/etc/rc.d/rc.local line= "IP LINK SET {{ NETWORK_CARD }} promisc on " #添加 open NIC Mixed mode must be turned on or docker macvlan cannot access the outside network- name: ip link set {{ network_card }} promisc on Open Immediate effect shell: ip link set {{ network_card }} promisc on- name: docker network ls |grep macvlan shell: docker network ls | grep macvlan # determine if docker macvlan nic is added register: result ignore_errors: True # Ignore error- name: create docker macvlan shell: docker network create -d macvlan --subnet={{ subnet }} -- gateway={{ gateway }} -o parent={{ network_card }} -o macvlan_mode=bridge {{ netname } } # configuring docker macvlan Nic when: result.rc == True #result Return to True execution
Other instructions:
Ansible-playbook-i hosts Site.yml-verbose performing Docker Macvlan using Docker run-it-d--net=eth0_1 (Docker macvlan nic name) p=192.168.2.210 (Docker IP) d0de804bd957 (docker image)/usr/sbin/init
centos7,6 base Image Production script Chinese support modify time zone Shanghai script
#!/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.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. The default is /etc/yum.conf for Centos/RHEL and /etc/dnf/dnf.conf for FedoraEOOPTS exit 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" while getopts ": Y:p:g:h" opt; do case $opt in y) yum_config= $OPTARG ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;H) usage ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;P) install_packages= "$OPTARG" ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;G) install_groups= "$OPTARG" ;; \?) echo "invalid option: - $OPTARG " usage ;; esacdoneshift $ ((optind - 1)) name=$1if [[ -z $name ]]; then usagefitarget=$ (mktemp -d --tmpdir $ (basename $0). XXXXXX) set -xmkdir -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/fiif [[ -n " $install _ Groups " ]];then yum -c " $yum _config " --installroot=" $target " - -releasever=/ --setopt=tsflags=nodocs --setopt=group _package_types=mandatory -y groupinstall $install _groupsfiif [[ -n "$install _ Packages " ]];then yum -c " $yum _config " --installroot=" $target " --releasever=/ --setopt=tsflags=nodocs -- setopt=group_package_types=mandatory -y install $install _packagesfiyum -c "$yum _ Config " --installroot=" $target "&Nbsp;-y clean allcat > "$target"/etc/sysconfig/network <<eofnetworking= yeshostname=localhost.localdomaineof#zh_cn datetime shanghairm -rf "$target"/etc/ localtimecp -d /etc/localtime "$target"/etc/localtime# effectively: febootstgap-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# reinstall glibc-common zh_cnyum --installroot= "$target" --releasever=/ --setopt=tsflags= Nodocs --setopt=group_package_types=mandatory -y reinstall glibc-commonyum -c "$yum _config" --installroot= "$target" -y clean allversion=for file in "$target"/etc/{redhat,system}-releasedo if [ -r "$file" ]; then version= "$ (sed ' s/^[^0-9\]*\ ([0-9.] \+\). *$/\1/' "$file") " break fidoneif [ -z "$version" ]; then echo >&2 " warning: cannot autodetect os version, using ' $name ' as tag " version= $namefi # cn langcat >> "$target"/etc/profile << EOFulimit -u 102400ulimit -n 102400ulimit -d unlimitedulimit -m Unlimitedulimit -s unlimitedulimit -v unlimitedulimit -t unlimitedulimit -c unlimitedexport lc_all= "ZH_CN. UTF-8 " export lang=" ZH_CN. UTF-8 "eoftar --numeric-owner -c -c " $target " . | docker import - $name: $versiondocker run -i -t --rm $name: $version /bin/bash -c ' Echo success ' rm -rf "$target"
This article is from the "Growth record" blog, so be sure to keep this source http://juestnow.blog.51cto.com/1515305/1877651
Batch install docker1.12 with Ansible CENTOS7 system and add Docker Macvlan network support