docker安装mysql

1、判断是否安装了

运行 docker 如果未找到命令

2、先安装docker

依次执行

sudo yum install -y yum-utils

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

启动

systemctl start docker

设置开机启动

systemctl enable docker

3、拉镜像

docker pull mysql

4、创建3个文件夹:数据,日志,配置文件

mkdir -p /appdata/mysql/data /appdata/mysql/logs /appdata/mysql/conf

如果要修改配置文件,把这个文件上传到/app/mysql/conf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/var/lib/mysql-files
user=mysql

pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysqld.sock

!includedir /etc/mysql/conf.d/

5、启动

docker run -itd --restart=always --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root密码 -v /appdata/mysql/logs:/var/log/mysql -v /appdata/mysql/data:/var/lib/mysql -v /appdata/mysql/conf:/etc/mysql/conf.d mysql

docker update mysql --restart=always

6、开端口

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --reload

你可能感兴趣的:(docker,mysql)