[root@test php-fpm]# cat Dockerfile
from centos:centos6
ADD Centos-6.repo /etc/yum.repos.d/CentOS-Base.repo
ADD epel-6.repo /etc/yum.repos.d/epel.repo
add php-5.5.38 /php-5.5.38
RUN yum -y groupinstall "Desktop Platform Development"
RUN yum -y install libmcrypt-devel bzip2-devel gcc openssl-devel php-mcrypt libmcrypt
RUN cd /php-5.5.38 && ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-bz2 --enable-fpm --with-gd && make && make install
RUN cp /php-5.5.38/php.ini-production /usr/local/php/etc/php.ini
RUN mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
RUN useradd -M -s /sbin/nologin php
RUN sed -i -e 's\;pid = run/php-fpm.pid\pid = run/php-fpm.pid\g' -e 's\nobody\php\g' -e 's\listen = 127.0.0.1:9000\listen = 0.0.0.0:9000\g' /usr/local/php/etc/php-fpm.conf
RUN sed -i 's\;daemonize = yes\daemonize = no\g' /usr/local/php/etc/php-fpm.conf
EXPOSE 9000
CMD ["/usr/local/php/sbin/php-fpm"]
8、开始构建php镜像:
[root@test php-fpm]# docker build -t lnmp/php:1.0 .
9、构建mysql镜像的Dockerfile:
[root@test mysql]# cat Dockerfile
FROM centos:centos6
MAINTAINER xiaoluo "18878774@163.com"
RUN yum install -y mysql-server mysql
ADD ./startup.sh /opt/startup.sh
RUN chmod +x /opt/startup.sh
EXPOSE 3306
CMD ["/bin/bash","/opt/startup.sh"]
##启动脚本:
[root@test mysql]# cat startup.sh
#!/bin/bash
if [ ! -f /var/lib/mysql/ibdata1 ]; then
mysql_install_db
/usr/bin/mysqld_safe &
sleep 10s
mysql -e "grant all privileges on *.* to 'root'@'%' identified by '123456'; FLUSH PRIVILEGES;"
killall mysqld
sleep 10s
fi
/usr/bin/mysqld_safe
**正常启动的时候,是没有问题的;当时当我们用-v做持久化的时候,好像说用户就失去对/var/lib/mysql的控制权,所以启动的时候我们要判断初始化才可以用-v来持久化相关目录,这个地方之前搞了好久就是挂不起来,后面原来是这个地方。
10、开始构建mysql镜像:
[root@test mysql]# docker build -t lnmp/mysql:1.0 .
11、下面我们开始启动相关容器:
[root@test web]# docker run -dit --name php -v /web:/web lnmp/php:1.0
[root@test web]# docker run -dit --name web -p 80:80 -v /web:/web --link php:php lnmp/nginx:1.0
[root@test web]#docker run -dit --name mysql -p 3306:3306 -v /opt/data:/var/lib/mysql lnmp/mysql:1.0
#####
[root@test mysql]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3527cddb4c50 lnmp/mysql:1.0 "/bin/bash /opt/st..." 4 seconds ago Up 3 seconds 0.0.0.0:3306->3306/tcp mysql
fab93953c438 lnmp/nginx:1.0 "/usr/local/nginx/..." About a minute ago Up About a minute 0.0.0.0:80->80/tcp web
d5854337c10b lnmp/php:1.0 "/usr/local/php/sb..." 3 minutes ago Up 2 minutes 9000/tcp php
##可以看到我们已经都启动了所有的容器了。
12、接下来我们登录一下mysql.创建一下wordpress使用的数据库:
[root@test mysql]# mysql -uroot -p123456 -h 192.168.63.200
MySQL [(none)]> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
13、然后我们把wordpress代码放到我们挂载的本地/web目录下面:
[root@test web]# wget https://cn.wordpress.org/wordpress-4.7.2-zh_CN.tar.gz
#然后解压出来。我们直接访问一下当前主机的IP地址:
直接往下走注册即可: