码迷,mamicode.com
首页 > 数据库 > 详细

DockerFile部署lnmp+memcached+redis+mongodb开发环境for MySQL(二)

时间:2018-09-21 10:52:57      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:des   process   客户   cal   months   火墙   perm   memcached   准备   

本文源链接地址: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="1012405802@qq.com" 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(二)

标签:des   process   客户   cal   months   火墙   perm   memcached   准备   

原文地址:https://www.cnblogs.com/93bok/p/9684964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!