docker_install.sh

 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 }

 

转载于:https://www.cnblogs.com/zhj5551/p/11198318.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值