二进制安装docker-ce
一、安装
cd ~
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.6.tgz
tar xzvf docker-20.10.6.tgz
cp docker/* /usr/bin/
rm docker-20.10.6.tgz -rf
rm docker -rf
二、配置docker启动
tee /usr/lib/systemd/system/dockerd.service >/dev/null <<EOF
[Unit]
Description=Docker Daemon Service
[Service]
ExecStart=/usr/bin/dockerd
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=docker daemon
User=root
[Install]
WantedBy=multi-user.target
EOF
三、配置docker镜像源
mkdir /etc/docker
tee /etc/docker/daemon.json >/dev/null <<EOF
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
EOF
四、启动docker
systemctl enable dockerd
systemctl start dockerd
五、安装mysql
六、运行mysql
1.文件解析
/home/mysql/conf.d/docker.cnf 此文件默认为 [mysqld] 组,监听端口等配置在此。
/home/mysql/conf.d/mysql.cnf 此文件为客户端配置,配置组为[mysql]。
2.命令行
mkdir -p /home/mysql/conf.d
touch /home/mysql/conf.d/docker.cnf >/dev/null <<EOF
[mysqld]
skip-host-cache
skip-name-resolve
bind-address = 0.0.0.0
port = 3306
character-set-client-handshake = false
character-set-server = utf8mb4
init_connect=‘SET NAMES utf8mb4‘
EOF
tee /home/mysql/conf.d/mysql.cnf >/dev/null <<EOF
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
EOF
运行 mysql
默认将配置文件放在 /home/mysql/conf.d
否则将 /home/mysql/database
docker run --name mysql -d -p 3306:3306 -v /home/mysql/conf.d:/etc/mysql/conf.d -v /home/mysql/database:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=mysql -e MYSQL_USER=mysql -e MYSQL_PASSWORD=mysql mysql:8.0.25