通过 RPM 安装 docker 17.03.0 版本并且配置 docker 阿里加速
安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2
添加软件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新并安装Docker-CE
yum makecache fast
yum install -y --setopt=obsoletes=0 docker-ce-17.03.1.ce-1.el7.centos docker-ce-selinux-17.03.1.ce-1.el7.centos
配置阿里云加速
网站 https://cr.console.aliyun.com/
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://c0hr9jut.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
通过 docker 安装一个 LAPM 架构
安装docker并启动
apt -y install docker
systemctl start docker
下载wordpress容器和mariadb容器
[root@ubuntu18 ~]#docker pull mariadb
[root@ubuntu18 ~]#docker pull wordpress
启动mariadb容器
[root@ubuntu18 ~]#docker run --name mariadb -d -e MYSQL_ROOT_PASSWORD=heshizhe -p 3306:3306 mariadb:10.5
7854812c32ec51b3ca62ac5a1c51aa538110ffee7749b1bfebea699e94068714
[root@ubuntu18 ~]#docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7854812c32ec mariadb:10.5 "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:3306->3306/tcp mariadb
进入mariadb容器创建数据库和授权账号
[root@ubuntu18 ~]#docker exec -it mariadb bash
root@7854812c32ec:/# mysql -uroot -pheshizhe
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.8-MariaDB-1:10.5.8+maria~focal mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> grant all on wordpress.* to wordpress@'%' identified by 'heshizhe';
Query OK, 0 rows affected (0.001 sec)
启动wordpress容器
[root@ubuntu18 ~]#docker run --name wordpress --link mariadb:mariadb -p 80:80 -d wordpress
63f88ff402c12de2e146b9280247595721ce452998fc93bd6eac6840cc04ccd5
[root@ubuntu18 ~]#docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
63f88ff402c1 wordpress "docker-entrypoint.s…" 4 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp wordpress
7854812c32ec mariadb:10.5 "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp mariadb
bmV0L3FxXzQyNDI3NTk0,size_16,color_FFFFFF,t_70#pic_center)
写出 docker run 命令的延申指令,如怎么在停止一个 docker 容器的时候自动删除该容器
docker run -rm nginx
写出 docker run 命令在自动启动 docker 服务时通过什么参数能够启动 docker 中的容器,从而实现容器随着 docker 服务的启动而自动启动
docker run -d -it --restart always nginx