Dockerfile 构建mysql镜像
Dockerfile 构建mysql镜像1,建立文件2,构建my.cnf文件3,构建Dockerfile文件4,构建镜像5,构建容器6,进入容器给权限7,登录mysql8,在宿主机yum安装msyql9,客户端连接MySQL容器1,建立文件mkdir mysqld2,构建my.cnf文件cd mysqldvim my.cnf[client]port = 3306socket=/usr/local/
·
Dockerfile 构建mysql镜像
1,建立文件
mkdir mysqld
2,构建my.cnf文件
cd mysqld
vim my.cnf
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
3,构建Dockerfile文件
vi Dockerfile
FROM centos:7
RUN yum -y install \
ncurses \
ncurses-devel \
bison \
cmake \
make \
gcc \
gcc-c++
RUN useradd -s /sbin/nologin mysql
ADD mysql-boost-5.7.20.tar.gz /usr/local/src
WORKDIR /usr/local/src/mysql-5.7.20/
RUN cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1 && make -j4 && make install
RUN chown -R mysql:mysql /usr/local/mysql/
RUN rm -rf /etc/my.cnf
ADD my.cnf /etc
RUN chown mysql:mysql /etc/my.cnf
ENV PATH=/usr/local/mysql/bin/:/usr/local/mysql/lib:$PATH
WORKDIR /usr/local/mysql/
RUN /usr/local/mysql/bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
RUN cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
EXPOSE 3306
RUN echo -e "#!/bin/sh \nsystemctl enbale mysqld" > /run.sh
RUN chmod 755 /run.sh
RUN sh /run.sh
CMD ["init"]
4,构建镜像
docker build -t mysql:centos .
5,构建容器
docker run -d --name=mysql--server -P --privileged msyql:centos
6,进入容器给权限
docker exec -it 容器id /bin/bash
7,登录mysql
mysql -u root -p #登录MySQL //如果无法无密码登录,可以回宿主机查看/etc/my.cnf 文件,将其清空
grant all privileges on *.* to 'root'@'%' identified by '123456';
grant all privileges on *.* to 'root'@'localhost' identified by '123456';
flush privileges;
exit
8,在宿主机yum安装msyql
yum -y install mysql
9,客户端连接MySQL容器
- 这时候进入宿主机通过ip地址是可以共享mysql的
更多推荐
所有评论(0)