docker重新打包MySQL5.7镜像

Posted Manger

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker重新打包MySQL5.7镜像相关的知识,希望对你有一定的参考价值。

1:先下载mysql镜像
# docker pull  mysql:5.7
 
2:运行镜像生成容器
# docker run --name mysql -p 3306:3306 -e MYSQL\_ROOT\_PASSWORD=123456  -d mysql:5.7
 
3:查看生成最新的容器
# docker ps -l
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
64f075017f93        mysql:5.7                  "docker-entrypoint..."   17 minutes ago      Exited (1) 16 minutes ago                                 mysql
 
4:进入容器查看是否安装成功
# docker exec -it mysql  bash
 
[email protected]:/# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.22-log MySQL Community Server (GPL)
 
Copyright (c) 2000, 2018, 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 [(none)]>
 
5:宿主机登录测试MySQL
# mysql -uroot -p123456 -h192.168.1.20
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.22-log MySQL Community Server (GPL)
 
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
 
Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.
 
MySQL [(none)]>
 
6:修改my.cnf配置文件
 
my.cnf配置文件
技术分享图片
# cat > /etc/mysql/my.cnf <<END
[client]
port = 3306
socket   = /var/run/mysqld/mysqld.sock
 
[mysqld]
port = 3306
socket  = /var/run/mysqld/mysqld.sock
back_log = 80
basedir = /usr
tmpdir = /tmp
datadir = /var/lib/mysql
 
#-------------------gobal variables------------#
slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=16
slave_preserve_commit_order= on
gtid_mode = ON
relay_log_info_repository = TABLE  
master_info_repository    = TABLE  
relay_log_recovery        = on
enforce_gtid_consistency = ON
binlog_checksum = NONE
log_slave_updates = ON
log-bin = /var/lib/mysql/mysql-bin
max_connect_errors = 20000
max_connections = 2000
wait_timeout = 3600
interactive_timeout = 3600
net_read_timeout = 3600
net_write_timeout = 3600
table_open_cache = 1024
table_definition_cache = 1024
thread_cache_size = 512
open_files_limit = 10000
character-set-server = utf8
collation-server = utf8_bin
skip_external_locking
performance_schema = 1
user = mysql
myisam_recover_options = DEFAULT
skip-name-resolve
local_infile = 0
lower_case_table_names = 0
 
#--------------------innoDB------------#
innodb_buffer_pool_size = 2000M
innodb_data_file_path = ibdata1:200M:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_io_capacity = 600
innodb_lock_wait_timeout = 120
innodb_log_buffer_size = 8M
innodb_log_file_size = 200M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 85
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_support_xa = 1
innodb_thread_concurrency = 32
innodb_file_per_table
innodb_rollback_on_timeout
 
#------------session variables-------#
join_buffer_size = 8M
key_buffer_size = 256M
bulk_insert_buffer_size = 8M
max_heap_table_size = 96M
tmp_table_size = 96M
read_buffer_size = 8M
sort_buffer_size = 2M
max_allowed_packet = 64M
read_rnd_buffer_size = 32M
 
#------------MySQL Log----------------#
log-bin = my3306-bin
binlog_format = row
sync_binlog = 1
expire_logs_days = 15
max_binlog_cache_size = 128M
max_binlog_size = 500M
binlog_cache_size = 64k
slow_query_log
log-slow-admin-statements
log_warnings = 1
long_query_time = 0.25
 
#---------------replicate--------------#
relay-log-index = relay3306.index
relay-log = relay3306
server-id =88
init_slave = set sql_mode=STRICT_ALL_TABLES
log-slave-updates
[myisamchk]
key_buffer = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysql]
prompt=MySQL [\d]>
default-character-set=utf8  
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
log-error = /var/lib/mysql/mysqld_error.log
END
View Code

 

 
7:生成新的镜像
# docker commit 64f075017f93  mysql:5.7.22
 
8:查看镜像
# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
mysql                        5.7.22              1bc73a7082d4        20 minutes ago      372MB
mysql                        5.7                     66bc0f66b7af        2 weeks ago         372MB
 
9:测试新的镜像是否生效
# docker run --name mysql_test  -p 3306:3306 -e MYSQL\_ROOT\_PASSWORD=123456  -d mysql:5.7.22
# docker exec -it mysql_test  bash   
查看/etc/mysql/my.cnf配置文件
 
宿主机登陆测试MySQL数据库
# mysql -uroot -p123456 -h192.168.1.20
 
 
 
 

以上是关于docker重新打包MySQL5.7镜像的主要内容,如果未能解决你的问题,请参考以下文章

docker安装mysql5.7

docker安装mysql5.7

Docker安装mysql5.7

docker安装mysql5.7

系列6使用Dockerfile创建带mysql5.7的Centos Docker镜像1

Docker中运行MySQL5.7并挂载宿主机目录到镜像