首页 > 其他 > 详细

Docker

时间:2020-11-15 23:09:57      阅读:34      评论:0      收藏:0      [点我收藏+]

1、通过 RPM 安装 docker 17.03.0 版本并且配置 docker 阿里加速

 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启动失败,请检查配置文件"

2、通过 docker 安装一个 LAPM 架构

 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 ......

3、写出 docker run 命令的延申指令,如怎么在停止一个 docker 容器的时候自动删除该容器

1 docker run --rm -it alpine

4、写出 docker run 命令在自动启动 docker 服务时通过什么参数能够启动 docker 中的容器,从而实现容器随着 docker 服务的启动而自动启动

1 docker run -d --restart=always nginx

 

Docker

原文:https://www.cnblogs.com/hrong/p/13978945.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!