写一个 构建镜像mysql5.7的dockerfile
时间: 2023-11-30 12:40:10 浏览: 104
以下是构建镜像mysql5.7的Dockerfile:
```dockerfile
# 基于centos7镜像构建
FROM centos:7
# 安装必要的软件包
RUN yum -y update && \
yum -y install wget && \
yum -y install tar && \
yum -y install bzip2 && \
yum -y install vim && \
yum -y install net-tools && \
yum -y install gcc && \
yum -y install make && \
yum -y install cmake && \
yum -y install ncurses-devel && \
yum -y install openssl-devel && \
yum -y install libaio-devel && \
yum -y install perl && \
yum -y install numactl && \
yum -y install numactl-devel && \
yum -y install libevent-devel && \
yum -y install git && \
yum -y install epel-release && \
yum -y install pwgen && \
yum -y install python-pip && \
yum -y install python-devel && \
yum -y install python-setuptools && \
yum -y install python-wheel && \
yum -y install python3-pip && \
yum -y install python3-devel && \
yum -y install python3-setuptools && \
yum -y install python3-wheel && \
yum clean all
# 下载mysql5.7安装包
RUN wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
# 解压mysql安装包
RUN tar -zxvf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz && \
mv mysql-5.7.35-linux-glibc2.12-x86_64 /usr/local/mysql && \
rm -f mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
# 添加mysql用户和用户组
RUN groupadd mysql && \
useradd -r -g mysql -s /bin/false mysql
# 修改mysql目录权限
RUN chown -R mysql:mysql /usr/local/mysql && \
chmod -R 755 /usr/local/mysql
# 配置mysql环境变量
ENV PATH=$PATH:/usr/local/mysql/bin
# 复制mysql配置文件到容器中
COPY my.cnf /etc/my.cnf
# 复制mysql初始化脚本到容器中
COPY init_mysql.sh /usr/local/mysql/init_mysql.sh
# 修改mysql初始化脚本权限
RUN chmod +x /usr/local/mysql/init_mysql.sh
# 初始化mysql
RUN /usr/local/mysql/init_mysql.sh
# 暴露3306端口
EXPOSE 3306
# 启动mysql
CMD ["mysqld", "--user=mysql"]
```
其中,my.cnf是mysql的配置文件,init_mysql.sh是mysql的初始化脚本。在Dockerfile中,我们首先安装了mysql所需的软件包,然后下载并解压mysql安装包,接着添加mysql用户和用户组,修改mysql目录权限,配置mysql环境变量,复制mysql配置文件和初始化脚本到容器中,最后运行初始化脚本并启动mysql服务。
阅读全文