创建Mysql服务的Centos Docker镜像

一、准备dockerfile

mkdir mysql_centos

cd mysql_centos

cat Dockerfile

FROM nginx_dockerfile:centos
RUN yum -y install gcc gcc-c++ make automake cmake
RUN groupadd mysql; useradd -r -M -u 39 -s /sbin/nologin -g mysql mysql
RUN mkdir /usr/local/mysql; mkdir /data/mysql/db -p
RUN yum install gcc gcc-c++ ncurses-devel bison bison-devel -y
RUN wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.29.tar.gz
RUN tar zxf mysql-5.6.29.tar.gz -C /usr/src/
WORKDIR /usr/src/mysql-5.6.29
RUN cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/db -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DEXTRA_CHARSETS=all -DDEFAULT_COLLATION=utf8_general_ci -DWITH-MYSQLD-LDFLAGS=-all-static -DWITH-CLIENT-LD-FLAGS=-all-static -DWITH_DEBUG=0 && gmake && gmake install
RUN chown -R root:mysql /usr/local/mysql/ && chown -R mysql:mysql /data/mysql/db/
RUN chmod 775 /usr/src/mysql-5.6.29/scripts/mysql_install_db.sh
RUN /usr/src/mysql-5.6.29/scripts/mysql_install_db.sh --basedir=/usr/local/mysql --datadir=/data/mysql/db --no-defaults --user=mysql
RUN cp /usr/src/mysql-5.6.29/support-files/my-default.cnf /etc/my.cnf
RUN cp /usr/src/mysql-5.6.29/support-files/mysql.server /etc/init.d/mysqld
RUN chmod -R 775 /etc/init.d/mysqld && /etc/init.d/mysqld start
RUN echo -e '#!/bin/bash\nexport PATH=$PATH:/usr/local/mysql/bin' >/etc/profile.d/mysql.sh
RUN source /etc/profile

二、根据Dockerfile生成

docker build -t mysql_dockerfile:nginx_dockerfile .


docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

mysql_dockerfile    nginx_dockerfile    e8fcca4ad7b0        11 minutes ago      5.54GB

nginx_dockerfile    centos              28d333149027        3 days ago          692MB

nginx               centos              bb2863c49d58        3 days ago          586MB

sshd-centos         latest              0742cfe06535        3 days ago          328MB

centos              latest              36540f359ca3        3 weeks ago         193MB

Logo

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

更多推荐