1、通过 RPM 安装 docker 17.03.0 版本并且配置 docker 阿里加速
# 使用阿里云镜像站:https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/
# 删除旧的docker
sudo yum -y remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine docker-ce
# 删除
[root@centos7 ~]# rm -rf /var/lib/docker
[root@centos7 ~]# yum -y update
## 需要注意17.03.0 需要安装两个包
#docker-ce-selinux-17.03.2.ce-1.el7
[root@centos7 ~]# yum -y install https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch.rpm
##docker-ce-17.03.0.ce-1.el7
[root@centos7 ~]# yum -y install https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-17.03.0.ce-1.el7.centos.x86_64.rpm
# 查看版本
[root@centos7 ~]# docker version
Client:
Version: 17.03.0-ce
API version: 1.26
Go version: go1.7.5
Git commit: 3a232c8
Built: Tue Feb 28 08:10:07 2017
OS/Arch: linux/amd64
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
# 注册阿里云账号,复制镜像加速器地址信息
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
[root@centos7 ~]# sudo mkdir -p /etc/docker
[root@centos7 ~]# sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://crxyz1c2.mirror.aliyuncs.com"]
}
EOF
{
"registry-mirrors": ["https://crxyz1c2.mirror.aliyuncs.com"]
}
[root@centos7 ~]# sudo systemctl daemon-reload
[root@centos7 ~]# sudo systemctl restart docker
2、通过 docker 安装一个 LAPM 架构
[root@centos7 ~]# docker rm -f `docker ps -a -q`
a5988b6dca04
[root@centos7 ~]# docker rmi -f `docker images -q`
# 拉取centos镜像
[root@centos7 ~]# docker pull centos
# 创建实例并后台运行容器
[root@centos7 ~]# docker run -itd -p 80:80 --restart=always --name lap --privileged centos /usr/sbin/init
# 进入lap容器
[root@centos7 ~]# docker exec -it lap /bin/bash
[root@d1c2905cff9d /]# yum update -y
# 下载相关依赖包
[root@d1c2905cff9d /]# yum -y install httpd php php-json php-mysqlnd
# 下载wordpress,速度很慢,需要翻墙
[root@d1c2905cff9d /]# yum -y install wget lrzsz gzip
[root@d1c2905cff9d /]# wget https://cn.wordpress.org/latest-zh_CN.zip
# 建议window下载到本地,然后使用rz上传
[root@d1c2905cff9d /]# rz
[root@d1c2905cff9d /]# ls
bin latest-zh_CN.zip media root sys wordpress5.4-zh_CN.tar.gz
dev lib mnt run tmp
etc lib64 opt sbin usr
home lost+found proc srv var
[root@d1c2905cff9d /]# tar xf wordpress5.4-zh_CN.tar.gz -C /var/www/html/
[root@d1c2905cff9d /]# chown -R apache.apache /var/www/html/wordpress
[root@5778298223b4 /]# systemctl enable --now httpd
# 同时安装:ctrl+q+p,退出容器,但不停止容器
# 拉取mariadb数据库
[root@centos7 ~]# docker run -d -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 mariadb
[root@centos7 ~]# yum -y install mariadb
[root@centos7 ~]# mysql -uroot -p123456 -h 10.0.0.71 -P 3306
mysql> create database wordpress;
mysql> grant all on *.* to wordpress@"10.0.0.%" identified by "123456";
mysql> flush privileges;
mysql> exit
# 浏览器访问:10.0.0.71/wordpress,然后进行数据库相关操作
3、写出 docker run 命令的延申指令,如怎么在停止一个 docker 容器的时候自动删除该容器
# 运行容器
docker run hello-world
# 运行容器并指定唯一名字
docker run --name hello-test01 hello-world
# 运行容器并进行交互式操作
docker run -it --name hello-test02 hello-world
# 运行容器并指定容器的主机名
docker run --name hello-test03 -h hello hello-world
# 一次性运行容器,退出后立即删除,用于测试
docker run --rm alpine echo "hello world"
# 后台启动运行容器
docker run -d --name mysql mysql
# 启动容器并进行端口映射
docker run -d -p 8080:80 --name www httpd
4、写出 docker run 命令在自动启动 docker 服务时通过什么参数能够启动 docker 中的容器,从而实现容器随着 docker 服务的启动而自动启动
方式一:
在使用docker run启动容器时,使用--restart参数来设置
docker run -d -p 8080:80 --restart=always --name www httpd
方式二:
如果创建时未指定 --restart=always ,可通过update 命令设置
docker run -d -p 8080:80 --name www httpd
ocker update --restart=always www