十三、Dockerfile部署mysql8并挂载宿主机目录

作者: 温新

分类: 【Docker】

阅读: 4514

时间: 2020-12-13 05:41:05

Dockerfile构建mysql8.0.20

# 指定基础镜像
FROM centos:7
# 指定作者信息
MAINTAINER ziruchu
# 指定标签信息
LABEL author="ziruchu" createTime="2020-12-12"
# 安装依赖
RUN yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel make  bison ncurses ncurses-devel 
# 添加用户与组
RUN groupadd mysql && useradd -g mysql mysql -M -s /sbin/nologin
# 卸载数据库
RUN yum -y remove mariadb* boost-*
# 安装mysql依赖
ADD rpcsvc-proto-1.4.tar.gz /usr/local/src
ADD cmake-3.15.4.tar.gz /usr/local/src
# 切换工作目录
WORKDIR /usr/local/src/rpcsvc-proto-1.4
# 编译安装
RUN ./configure && make && make install
WORKDIR /usr/local/src/cmake-3.15.4
RUN ./bootstrap --prefix=/usr/local/cmake3 && gmake && gmake install
RUN ln -s /usr/local/cmake3/bin/cmake /usr/bin/
# 切换工作目录
WORKDIR /usr/local/src
# 添加mysql8
ADD mysql-boost-8.0.20.tar.gz /usr/local/src
# 切换工作目录
WORKDIR /usr/local/src/mysql-8.0.20
RUN mkdir build
WORKDIR /usr/local/src/mysql-8.0.20/build
# 编译安装
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql8 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DSYSCONFDIR=/etc \
-DWITH_EXTRA_CHARSETS=all \
-DMYSQL_DATADIR=/usr/local/mysql8/data \
-DWITH_BOOST=/usr/local/src/mysql-8.0.20/boost \
-DDOWNLOAD_BOOST=1 \
-DFORCE_INSOURCE_BUILD=1
RUN make && make install
# 修改mysql组与用户
RUN chown -R mysql:mysql /usr/local/mysql8/
RUN chmod  -R 755 /usr/local/mysql8/
# 初始化mysql
RUN /usr/local/mysql8/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql8/data --character-set-server=utf8
# 安装ssl
RUN /usr/local/mysql8/bin/mysql_ssl_rsa_setup
# 设置环境变量
ENV PATH $PATH:/usr/local/mysql8/bin
# 暴露端口
EXPOSE 3306
CMD ["mysql",-g","daemon off"]

【未成功】

2020-12-12

请登录后再评论