1 #!/bin/bash 2 #by zhangjia 3 #2019年4月8日21:56:44 4 #install docker 5 ###################################333 6 set -x 7 8 install_docker() { 9 uname -r 10 yum -y update 11 yum -y remove docker docker-common docker-selinux docker-engine 12 yum install -y yum-utils device-mapper-persistent-data lvm2 13 #使用下列命令设置 stable 镜像仓库。您始终需要使用 stable 镜像仓库,即使您还需要通过 edge 或 testing 镜像仓库安装构建也是如此。 14 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 15 yum list docker-ce --showduplicates | sort -r 16 sudo yum makecache fast 17 yum -y install docker-ce 18 systemctl enable docker 19 systemctl restart docker 20 systemctl status docker 21 docker version 22 docker network create --subnet=10.1.0.0/16 docker_network 23 docker network ls 24 docker pull centos 25 } 26 build_centos_sshd() { 27 #useradd docker && echo "5" |passwd --stdin docker 28 #build centos cantiner and sshd server 29 sshd_port="6122" 30 ip="10.1.0.10" 31 #docker images 32 docker run -itd \ 33 --privileged \ 34 --restart=always \ 35 -v /data/docker:/data/mycontainer:rw \ 36 -p ${sshd_port}:22 -p 7180:80 \ 37 --name nginx_1_${ip} \ 38 --net docker_network \ 39 --ip ${ip} \ 40 centos \ 41 /usr/sbin/init 42 43 docker inspect -f='{{.Name}} -- {{.NetworkSettings.Networks.docker_network.IPAddress}} -- {{.HostConfig.PortBindings}} ' $(docker ps -aq) 44 #install sshd server 45 docker exec -it `docker ps -a| grep ${sshd_port}|grep '/usr/sbin/init'|awk '{print $1}'` yum install -y openssh-server vim net-tools 46 docker exec -it `docker ps -a| grep ${sshd_port}|grep '/usr/sbin/init'|awk '{print $1}'` systemctl enable sshd 47 docker exec -it `docker ps -a| grep ${sshd_port}|grep '/usr/sbin/init'|awk '{print $1}'` systemctl start sshd 48 docker exec -it `docker ps -a| grep ${sshd_port}|grep '/usr/sbin/init'|awk '{print $1}'` systemctl stauts sshd 49 systemctl stop getty@tty1.service ; systemctl mask getty@tty1.service ; systemctl daemon-reload 50 for i in `docker ps -aq`;do docker exec -it $i systemctl stop getty@tty1.service;docker exec -it $i systemctl mask getty@tty1.service;docker exec -it $i systemctl daemon-reload;done 51 docker exec -it `docker ps -a| grep ${sshd_port}|grep '/usr/sbin/init'|awk '{print $1}'` passwd root 52 } 53 install_docker 54 #build_centos_sshd 55 56 # curl -XGET http://registry_ip:5000/v2/_catalog 57 # curl -XGET http://registry_ip:5000/v2/image_name/tags/list 58 59 user_commnd() { 60 for i in `docker ps -aq`;do docker inspect $i | grep -i ipaddr|tail -1|awk -F ':' '{print "'$i'""--"$2}'|sed -e 's/\"//g' -e 's/\,//g' -e 's/\ //g';done 61 }