Centos 7.X 安装docker
1 #!/bin/bash 2 # centos/7 install docker docker-compose docker-enter 3 4 # 错误输出 5 error_echo(){ 6 echo -en "\033[40;31m ########################### \033[0m\n" 7 echo -en "\033[40;31m ${data} \033[0m\n" 8 echo -en "\033[40;31m ########################### \033[0m\n" 9 }10 11 # 成功输出12 success_echo(){13 echo -en "\033[40;32m ########################### \033[0m\n"14 echo -en "\033[40;32m ${data} \033[0m\n"15 echo -en "\033[40;32m ########################### \033[0m\n"16 }17 18 19 # 安装docker 服务20 install_docker_server(){21 yum -y install yum-utils22 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo23 # install docker 24 /usr/bin/yum -y install docker-ce25 # change docker server config26 if [ -f /usr/lib/systemd/system/docker.service ];then27 /usr/bin/sed -i 's#ExecStart=/usr/bin/dockerd#ExecStart=/usr/bin/dockerd -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -g /opt/docker -s devicemapper --storage-opt dm.fs=xfs --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true --storage-opt dm.basesize=5G#g' /usr/lib/systemd/system/docker.service28 else29 data="docker server install failure"30 error_echo 31 fi32 33 # start docker.server34 /usr/bin/systemctl start docker 35 }36 37 # 安装docker-compose命令38 install_docker_compose(){39 if [ ! -f /usr/bin/pip ];then40 # install python-pip 41 /usr/bin/yum -y install epel-release python-devel python-pip42 fi43 # install docker-compose44 data="docker-compose install success"45 /usr/bin/pip install docker-compose && success_echo46 }47 48 49 # 安装docker-enter命令50 install_docker_enter(){51 # install docker-enter52 data="docker-enter install success"53 /usr/bin/docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter && success_echo54 }55 56 57 58 59 main(){60 # docker 是否安装61 if [ ! -f /usr/bin/docker ];then62 install_docker_server63 else64 data="Docker has been installed"65 success_echo 66 fi67 # docker-compose 是否安装68 if [ ! -f /usr/bin/docker-compose ];then69 install_docker_compose70 else71 data="docker-compose has been installed"72 success_echo 73 74 fi75 # docker-enter 是否安装76 if [ ! -f /usr/local/bin/docker-enter ];then77 install_docker_enter78 else79 data="docker-enter has been installed"80 success_echo 81 fi82 }83 84 # 执行 main函数85 main