DockerFile部署lnmp+memcached+redis+mongodb开发环境for MySQL
Posted 93bok
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DockerFile部署lnmp+memcached+redis+mongodb开发环境for MySQL相关的知识,希望对你有一定的参考价值。
本文源链接地址:https://www.93bok.com
1、下载基础镜像centos
docker pull centos:6
2、查看一下大小
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 6 70b5d81549ec 2 months ago 195MB
3、创建文件夹存放mysql的Dockerfile,以及源码包等等,为后期docker-compose做准备
mkdir -p /data/docker/lnmp-test/dockerfile/mysql
4、创建MySQL的Dockerfile
vim /data/docker/lnmp-test/dockerfile/mysql/Dockerfile
FROM centos:6
LABEL maintainer="[email protected]" description="Mysql image"
ENV MYSQL_VERSION 5.6.25
COPY packages /root/packages
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 && CMAKE=" -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc/mysql -DMYSQL_DATADIR=/data/mysql -DWITH_SSL=system -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci" && yum -y install cmake gcc gcc-c++ ncurses-devel bison-devel bison openssl-devel perl perl-devel && groupadd mysql && useradd -M -s /sbin/nologin mysql -g mysql && tar -zxvf /root/packages/mysql-$MYSQL_VERSION.tar.gz -C /root/packages && cd /root/packages/mysql-$MYSQL_VERSION && cmake $CMAKE && make -j $(getconf _NPROCESSORS_ONLN) && make install && mkdir -p /etc/mysql && mkdir -p /data/mysql && cp support-files/my-default.cnf /etc/mysql/my.cnf && ln -s /usr/local/mysql/bin/* /usr/local/bin/ && cp /root/packages/startup.sh /root/startup.sh && chmod +x /root/startup.sh && rm -rf /root/packages && yum clean all
EXPOSE 3306
CMD ["/root/startup.sh"]
5、其中startup.sh的内容为
cat startup.sh
#!/bin/sh
chown -R mysql:mysql /data/mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mysql --user=mysql --defaults-file=/etc/mysql/my.cnf
/usr/local/mysql/support-files/mysql.server start
mysql -e "grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘;"
mysql -e "grant all privileges on *.* to ‘root‘@‘localhost‘ identified by ‘123456‘;"
/usr/local/mysql/support-files/mysql.server stop
/usr/local/mysql/bin/mysqld_safe
6、把mysql源码包和启动脚本的packages目录上传到/data/docker/lnmp-test/dockerfile/mysql/目录下
7、创建镜像
cd /data/docker/lnmp-test/dockerfile/mysql/
docker build -t centos6:mysql .
8、查看镜像大小
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos6 mysql 11017a938926 9 seconds ago 1.35GB
centos 6 70b5d81549ec 2 months ago 195MB
9、启动容器测试是否成功
docker run -d -p 3306:3306 --name mysql centos6:mysql
10、客户机连接mysql容器测试(宿主机开启防火墙3306端口)
11、宿主机开启防火墙3306端口
firewall-cmd --add-port=3306/tcp --permanent
systemctl restart firewalld
以上是关于DockerFile部署lnmp+memcached+redis+mongodb开发环境for MySQL的主要内容,如果未能解决你的问题,请参考以下文章
DockerFile部署lnmp+memcached+redis+mongodb开发环境for MySQL
DockerFile部署lnmp+memcached+redis+mongodb开发环境for Redis
DockerFile部署lnmp+memcached+redis+mongodb开发环境for Nginx