一、初始化centos系統指令碼
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
firewall-cmd --state
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all && yum makecache
yum update -y
二、國內源docker安裝指令碼
curl -sSL https://get.daocloud.io/docker | sh -s -- "--mirror" "Aliyun"
mkdir -p /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://6m7d428u.mirror.aliyuncs.com"],
"dns": ["114.114.114.114"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
EOF
systemctl enable docker && systemctl daemon-reload && systemctl restart docker
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
三、拉取MySQL映象
MySQL映象地址(選擇自己需要安裝的版本):
https://hub.docker.com/_/mysql?tab=tags&page=1&ordering=last_updated
拉取命令:docker pull mysql:5.7.33
四、啟動容器
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7.33
可以打下 docker images 看到當前拉取的映象
然後執行 docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7.33
mysql-test 是這個新建的容器的名稱 -p 3306:3306 是將容器內mysql預設要使用的3306的埠對映到當前虛擬機器的3306埠上
MYSQL_ROOT_PASSWORD=123456 是為安裝的mysql5.7.33設定預設的root賬戶的密碼 mysql:5.7.33是當前容器要用到的映象的名稱