分类: 虚拟化
2017-02-03 18:19:08
环境介绍:
操作系统:CentOS Linux release 7.3.1611 (Core)
Mysql版本:mysql-community-server-5.7.17
Docker 版本: 1.12.5
准备工作:下载mysql RPM安装包以及依赖包
-rw-r--r-- 1 root root 30044 Feb 3 14:28 numactl-libs-2.0.9-6.el7_2.x86_64.rpm
-rw-r--r-- 1 root root 21708 Feb 3 14:21 libaio-0.3.107-10.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 169496800 Nov 30 00:31 mysql-community-server-5.7.17-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2237116 Nov 30 00:30 mysql-community-libs-5.7.17-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 277812 Nov 30 00:29 mysql-community-common-5.7.17-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 25037548 Nov 30 00:29 mysql-community-client-5.7.17-1.el7.x86_64.rpm
mysql5.7.17 rpm安装包下载地址为:
在RPM相同目录下创建Dockerfile文件,内容如下:
FROM docker.zifang.com/centos7-base
MAINTAINER chicol "chicol@yeah.net"
# copy install package files from localhost.
ADD . /usr/local/src
# Add mysql user and group.
RUN groupadd mysql && \
useradd -r -g mysql mysql
RUN rpm -qa | grep mariadb | xargs -t -i rpm -e {} --nodeps
# Install dependency lib files.
RUN rpm -ivh /usr/local/src/numactl-libs-2.0.9-6.el7_2.x86_64.rpm && \
rpm -ivh /usr/local/src/libaio-0.3.107-10.el6.x86_64.rpm
# Install mysql-server and mysql-client.
RUN rpm -ivh /usr/local/src/mysql-community-common-5.7.17-1.el7.x86_64.rpm && \
rpm -ivh /usr/local/src/mysql-community-libs-5.7.17-1.el7.x86_64.rpm && \
rpm -ivh /usr/local/src/mysql-community-client-5.7.17-1.el7.x86_64.rpm && \
rpm -ivh /usr/local/src/mysql-community-server-5.7.17-1.el7.x86_64.rpm
# Config & Start mysql
RUN echo "user=mysql" >> /etc/my.cnf && \
mysqld --initialize
RUN chown -R mysql:mysql /var/lib/mysql && \
/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
RUN rm -rf /usr/local/src/*
WORKDIR ~
CMD /usr/sbin/init
生成镜像:
# docker build -t mysql:5.7.17 --force-rm .
[root@localhost mysql-5.7.17]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7.17 26e89a154c04 About an hour ago 2.197 GB
运行镜像:
# docker run -d --privileged --name=mysql mysql:5.7.17
# docker exec -it