1、 安裝docker
添加依賴
yum -y install yum-utils device-mapper-persistent-data lvm2
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安裝 yum -y install docker-ce
添加鏡像加速器
mkdir /etc/docker && vim /etc/docker/daemon.json 添加下列東西
{ "registry-mirrors": ["https://9cpn8tt6.mirror.aliyuncs.com"]
}
啓動 systemctl start docker 開機自動 systemctl enable docker
使用 mysql:5.7 鏡像創建 mysql 容器
docker run -dit -v /root/mysql/conf:/etc/mysql/conf.d -v /root/mysql/logs:/logs -v /root/mysql/data:/var/lib/mysql -p 3306:3306 --restart=always -e MYSQL_ROOT_PASSWORD=root --name mysql mysql:5.7
將 下列 mysql配置 放到/root/mysql/conf 目錄下 vim /root/mysql/conf/mysl.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
symbolic-links=0
character-set-server = utf8
#skip-networking
innodb_print_all_deadlocks = 1
max_connections = 2000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 80M
tmp_table_size = 16M
read_buffer_size = 20M
read_rnd_buffer_size = 8M
innodb_buffer_pool_size = 1G
sort_buffer_size = 8M
join_buffer_size = 128M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 24M
query_cache_limit = 2M
ft_min_word_len = 4
log-bin = mysql-bin
server-id = 1
binlog_format = mixed
performance_schema = 0
explicit_defaults_for_timestamp
lower_case_table_names = 1
interactive_timeout = 28800
wait_timeout = 28800
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
docker ps 查看 mysql 正常運行 用戶名和 密碼均是 root