[root@bogon ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@bogon ~]# yum -y install yum-utils device-mapper-persistent-data lvm2 container-selinux
[root@bogon ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@bogon ~]# yum install docker -y
https://cr.console.aliyun.com/#/accelerator
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://vtbf99sa.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
[root@bogon ~]# docker pull nginx:latest
[root@bogon ~]# docker pull mysql:8
[root@bogon ~]# docker pull bitnami/php-fpm
[root@bogon ~]# mkdir -pv /docker/www #网站根目录
mkdir: 已创建目录 "/docker"
mkdir: 已创建目录 "/docker/www"
[root@bogon ~]# mkdir -pv /docker/nginx/conf.d/
#nginx配置文件
mkdir: 已创建目录 "/docker/nginx"
mkdir: 已创建目录 "/docker/nginx/conf.d/"
[root@bogon ~]# mkdir -pv /docker/mysql
mkdir: 已创建目录 "/docker/mysql"
#数据库文件夹
[root@bogon ~]#
[root@bogon ~]# docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=598941324 -v /docker/mysql:/var/lib/mysql --name mysql8 mysql:8
528438949af0625fd7a936c49768d953c238f2d633614d2ef9cca74b9254843c
[root@bogon ~]# docker exec -it mysql8 /bin/bash
root@528438949af0:/# mysql -uroot -p598941324
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.15 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.00 sec)
mysql> alter user 'root'@'%' identified by '598941324';
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql>
[root@bogon ~]#
[root@bogon ~]# docker inspect mysql8 --format='{{.NetworkSettings.IPAddress}}'
#查看数据库ip
172.17.0.2
[root@bogon ~]#
[root@bogon ~]# mysql -h172.17.0.2 -uroot -p598941324
#重置密码
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.15 MySQL Community Server - GPL
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
MySQL 到此搭建完成