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

1、下载基础镜像centos
1
docker pull centos:6
2、查看一下大小
1
2
3
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 6 70b5d81549ec 2 months ago 195MB
3、创建文件夹存放MySQL的Dockerfile,以及源码包等等,为后期docker-compose做准备
1
mkdir -p /data/docker/lnmp-test/dockerfile/mysql
4、创建MySQL的Dockerfile
1
vim /data/docker/lnmp-test/dockerfile/mysql/Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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的内容为
1
cat startup.sh
1
2
3
4
5
6
7
8
#!/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、创建镜像
1
2
cd /data/docker/lnmp-test/dockerfile/mysql/
docker build -t centos6:mysql .
8、查看镜像大小
1
2
3
4
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos6 mysql 11017a938926 9 seconds ago 1.35GB
centos 6 70b5d81549ec 2 months ago 195MB
9、启动容器测试是否成功
1
docker run -d -p 3306:3306 --name mysql centos6:mysql

iSg9S0.png

10、客户机连接mysql容器测试(宿主机开启防火墙3306端口)

iSgkmF.png

iSgZk9.png

11、宿主机开启防火墙3306端口
1
2
firewall-cmd --add-port=3306/tcp --permanent
systemctl restart firewalld
博主QQ:1012405802
技术交流QQ群:830339411
版权声明:网站内容有原创和转载,如有侵权,请联系删除,谢谢!!
感谢打赏,93bok因你们而精彩!!(支付宝支持花呗)
0%