1 #!/bin/bash 2 VERSION="17.03.0.ce-1.el7" 3 4 echo "正在安装" 5 rpm -q docker-ce &> /dev/null && { echo "docker已安装" ; exit ; } 6 yum install -y wget &> /dev/null 7 wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo || { echo "配置docker源失败"; exit ; } 8 yum clean all 9 echo "正在安装的docker版本是$VERSION" 10 sleep 3 11 #yum install -y docker-ce-$VERSION docker-ce-cli-$VERSION &> /dev/null || { echo "docker安装失败"; exit ; } 12 yum install -y --setopt=obsoletes=0 docker-ce-${VERSION}.centos docker-ce-selinux-${VERSION}.centos 13 14 #阿里镜像加速 15 mkdir -p /etc/docker 16 cat > /etc/docker/daemon.json <<EOF 17 { 18 "registry-mirrors": ["https://h95skfl.mirror.aliyuncs.com"] 19 } 20 EOF 21 22 echo "docker安装成功" 23 systemctl daemon-reload 24 systemctl enable --now docker || echo "docker启动失败,请检查配置文件"
1 #查看lamp镜像 2 [08:48:30]root@yl:244 ~# docker search -s 100 lamp 3 Flag --stars has been deprecated, use --filter=stars=3 instead 4 NAME DESCRIPTION STARS OFFICIAL AUTOMATED 5 mattrayner/lamp A simple LAMP docker image running the prere… 240 [OK] 6 linode/lamp LAMP on Ubuntu 14.04.1 LTS Container 178 7 tutum/lamp Out-of-the-box LAMP image (PHP+MySQL) 141 8 greyltc/lamp a super secure, up-to-date and lightweight L… 100 [OK] 9 10 #拉去排名第一的镜像 11 [08:48:36]root@yl:245 ~# docker pull mattrayner/lamp 12 13 #将容器里端口映射到宿主机(注意端口冲突) 14 [08:48:36]root@yl:246 ~# docker run -d -p 80:80 -p 3306:3306 --name lamp mattrayner/lamp 15 16 #进入容器 17 [08:48:36]root@yl:247 ~# docker exec -it lamp bash 18 19 #查看数据库账号密码 20 [09:01:17]root@yl:39 ~# docker logs lamp 21 ...... 22 ======================================================================== 23 You can now connect to this MySQL Server with 3dKfq53sJ2Gm 24 25 mysql -uadmin -pasdf56arcGm -h<host> -P<port> 26 27 Please remember to change the above password as soon as possible! 28 MySQL user ‘root‘ has no password but only allows local connections 29 30 enjoy! 31 ======================================================================== 32 ......
1 docker run --rm -it alpine
1 docker run -d --restart=always nginx
原文:https://www.cnblogs.com/hrong/p/13978945.html