之前做过Docker 下mysql8.0 与本地mysql8.0的性能测试,测试结果可以参考:

https://blog.csdn.net/shiyu1157758655/article/details/86616675

现在就把docker下利用Dockerfile来搭建mysql的脚本奉上:

Dockerfile文件内容:

FROM centos:7.4.1708
#author
MAINTAINER shiyu
ENV DEBIAN_FRONTEND noninteractive
RUN  mkdir -p /usr/local/mysql
ADD  mysql /usr/local/mysql
#WORKDIR /usr/local/mysql
RUN  groupadd mysql
RUN  useradd -g mysql mysql
RUN  cd /usr/local
RUN  chmod 775  /usr/local/mysql
RUN  chown -R mysql.mysql /usr/local/mysql
RUN  yum -y install libaio-devel
RUN  yum -y install numactl
ENTRYPOINT sh /usr/local/mysql/start.sh

通过Dockfile创建镜像

[root@db-fh-197-102 local]# docker build -t centos:mysql .
[root@db-fh-197-102 local]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
centos              mysql               6a11fbeb3d89        12 minutes ago      4.37GB
centos              7.4.1708            295a0b2bd8ea        2 months ago         197MB

#创建容器

  1. [root@db-fh-197-102 local]# docker run --name mysql -p 5508:5508  -v /opt/mysql/:/usr/local/mysql/data -v  /usr/local/start.sh:/usr/local/mysql/start.sh -v /usr/local/my.cnf:/usr/local/mysql/my.cnf -d  centos:mysql
    备注:利用Dockerfile构建mysql测试环境,并且将本地/opt/mysql/ 挂载到镜像/usr/local/mysql/data,这样docker mysql的数据文件就会保存到本地路径下面。
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐