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
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
mkdir /etc/docker tee /etc/docker/daemon.json >/dev/null <<EOF { "registry-mirrors": ["http://hub-mirror.c.163.com"] } EOF
systemctl enable dockerd systemctl start dockerd
/home/mysql/conf.d/docker.cnf 此文件默认为 [mysqld] 组,监听端口等配置在此。
/home/mysql/conf.d/mysql.cnf 此文件为客户端配置,配置组为[mysql]。
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
默认将配置文件放在 /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