Dockerfile构建mysql数据库
dockerfile文件:
FROM centos:centos6
MAINTAINER admin "admin@topsec.com.cn"
RUN yum install -y mysql-server mysql
RUN /etc/init.d/mysqld start &&\
mysql -e "grant all privileges on *.* to 'root'@'%' identified by 'Talent123';"&&\
mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by 'Talent123';"&&\
mysql -u root -pTalent123 -e "show databases;"
mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by 'Talent123';"&&\
mysql -u root -pTalent123 -e "show databases;"
RUN rm -rf /etc/my.cnf
ADD my.cnf /etc/
EXPOSE 3306
CMD ["/usr/bin/mysqld_safe"]
单个构建my.cnf文件:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
lower_case_table_names = 1
character-set-server = utf8
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
lower_case_table_names = 1
character-set-server = utf8
max_connections = 5000
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
注:my.cnf文件和dockerfile文件应该放在一起;
构建容器命令:
docker build -t mysql_server .
docker run -ti --name=mysqlserver -d -p 3306:3306 mysql_server
mysql -h 127.0.0.1 -u root -pTalent23 -P 3306