docker 安装
Centos 7.X 安装docker
1 #!/bin/bash 2 3 # 成功输出 4 success_echo(){ 5 echo -en "\033[40;32m ########################### \033[0m\n" 6 echo -en "\033[40;32m ${1} \033[0m\n" 7 echo -en "\033[40;32m ########################### \033[0m\n" 8 } 9 10 # 错误输出 11 error_echo(){ 12 echo -en "\033[40;31m ########################### \033[0m\n" 13 echo -en "\033[40;31m ${1} \033[0m\n" 14 echo -en "\033[40;31m ########################### \033[0m\n" 15 } 16 17 function install_docker_server(){ 18 yum -y install yum-utils 19 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 20 # 安装docker-ce 21 /usr/bin/yum -y install docker-ce-${1} 22 # 更新docker 配置 23 if [ -f /usr/lib/systemd/system/docker.service ];then 24 /usr/bin/sed -i 's#^ExecStart=.*#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.service 25 else 26 error_echo "docker server install failure" 27 fi 28 # 设置docker 开机自启动 29 /usr/bin/systemctl enable docker 30 # 启动docker 服务 31 /usr/bin/systemctl start docker 32 } 33 34 35 # 安装docker-compose命令 36 install_docker_compose(){ 37 # 检查是否安装pip 38 if [ ! -f /usr/bin/pip ];then 39 # install python-pip 40 /usr/bin/yum -y install epel-release python-devel python-pip 41 fi 42 # install docker-compose 43 if [ -f /bin/docker-compose ];then 44 success_echo "Docker-compose is already installed" 45 else 46 /usr/bin/pip install docker-compose && success_echo "docker-compose install success" 47 fi 48 } 49 50 # 安装docker-enter命令 51 install_docker_enter(){ 52 # install docker-enter 53 which docker-enter 54 if [ $? -eq 0 ];then 55 success_echo "Docker-enter is already installed" 56 else 57 /usr/bin/docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter && success_echo "docker-enter install success" 58 fi 59 } 60 61 main(){ 62 DOCKER_VERSION=18.09.3 63 # 安装docker 64 install_docker_server ${DOCKER_VERSION} 65 # 安装 docker-compose 66 install_docker_compose 67 # 安装 docker-enter 68 install_docker_enter 69 } 70 71 main