# pwd /data # tree ./ -L 2 ./ ├── docker │ ├── dockerfile │ ├── lnmp.sh │ └── ser1.conf └── lnmp ├── mysql └── web 4 directories, 3 files2.dockerfile文件
# vim docker/dockerfile FROM centos:6 MAINTAINER garany@qq.com RUN rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm \ && yum install nginx mysql mysql-server mysql-devel php-fpm php-mysql -y \ && rm -rf /etc/nginx/conf.d/default.conf COPY ser1.conf /etc/nginx/conf.d/ ADD ./lnmp.sh /usr/local/sbin/ RUN chmod a+x /usr/local/sbin/lnmp.sh RUN /etc/init.d/mysqld start \ && mysqladmin -uroot password 123456 \ && mysql -uroot -p123456 -e"grant all privileges on *.* to root@'%' identified by '123456';" CMD /usr/local/sbin/lnmp.sh && tail -f EXPOSE 80 33063.nginx web配置文件
# vim docker/ser1.conf server { listen 80; server_name localhost; index index.html index.htm index.php; root /var/nginx; location ~ \.php$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }4.lnmp启动脚本
# vim docker/lnmp.sh #!/bin/bash /etc/init.d/nginx start /etc/init.d/php-fpm start /etc/init.d/mysqld start5.测试页面文件
# vim lnmp/web/index.php <?php header("Content-Type:text/html;charset=utf-8"); //date echo date("Y-m-d H:i:s")."<br /> \n"; //mysql $link=mysql_connect("localhost","root","123456"); if(!$link) echo "FAILD!The connection mysql_server fails"; else echo "OK!mysql_server is running"; //phpinfo phpinfo(); ?>6.生成镜像并启动容器
# cd docker # docker build -t lnmp ./ # docker images lnmp # docker run -itd --name lnmp_web -p 80:80 -p 3306:3306 -v /data/lnmp/web/:/var/nginx/ -v /data/lnmp/mysql/:/var/lib/mysql/ lnmp7.测试
# docker inspect -f {{.NetworkSettings}} lnmp_web
# mysql -h172.17.0.2 -uroot -p123456 -e"show processlist;"# elinks 127.0.0.1![]()
2017-09-13 21:22