目录
构建LAMP镜像(Dockerfile)
第一步 创建工作目录
第二步 编写dockerfile文件
Dockerfile文件配置内容
第三步 编写网页执行文件
第四步 编写启动脚本
第五步 赋权并且构建镜像
第六步 检查镜像
第七步 创建容器
第八步 浏览器测试
构建LAMP镜像(Dockerfile)
第一步 创建工作目录
mkdir -p /root/dockerfile/lamp
第二步 编写dockerfile文件
cd /root/dockerfile/lamp
vim Dockerfile
Dockerfile文件配置内容
FROM centos:7
MAINTAINER Liu
#安装Apache
RUN yum -y install zlib-devel gcc gcc-c++ pcre-devel wget perl make
run wget http://archive.apache.org/dist/httpd/httpd-2.2.17.tar.gz
run tar xf httpd-2.2.17.tar.gz
workdir httpd-2.2.17
run ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi && make && make install
expose 80
#安装Mysql
run yum -y install ncurses-devel
run wget http://www.cmake.org/files/v3.7/cmake-3.7.1.tar.gz
run tar xf cmake-3.7.1.tar.gz
workdir cmake-3.7.1
run ./configure && make && make install
run groupadd mysql
run useradd -M -s /sbin/nologin -g mysql mysql
run wget http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.22.tar.gz
run tar xf mysql-5.5.22.tar.gz
workdir mysql-5.5.22
run cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all && make && make install
run chown -R mysql:mysql /usr/local/mysql/
run rm -rf my.cnf
run cp support-files/my-medium.cnf /etc/my.cnf
run /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
run cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
run chmod 777 /etc/rc.d/init.d/mysqld
expose 3306
workdir /
run wget --no-check-certificate https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
run tar xf libmcrypt-2.5.8.tar.gz
workdir libmcrypt-2.5.8
run ./configure && make && make install
run ln -s /usr/local/lib/libmcrypt.* /usr/lib
workdir /
run wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
run tar xf mhash-0.9.9.9.tar.gz
workdir mhash-0.9.9.9
run ./configure && make && make install
run ln -s /usr/local/lib/libmhash* /usr/lib
workdir /
run wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
run tar xf mcrypt-2.6.8.tar.gz
workdir mcrypt-2.6.8
ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
run ./configure && make && make install
#安装PHP
run wget --no-check-certificate https://www.php.net/distributions/php-5.3.28.tar.gz
run yum -y install libpng libpng-devel pcre pcre-devel libxml2-devel libjepeg-devel
run tar xf php-5.3.28.tar.gz
workdir php-5.3.28
run ./configure --prefix=/usr/local/php5 --with-mcrypt --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql/ --with-config-file-path=/usr/local/php5 --enable-mbstring && make && make install
run cp php.ini-development /usr/local/php5/php.ini
run sed -i '226s/short_open_tag = Off/short_open_tag = On/g' /usr/local/php5/php.ini
workdir /
run wget http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
run tar xf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
workdir ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x
run cp ZendGuardLoader.so /usr/local/php5/lib/php/
run echo "zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so" >> /usr/local/php5/php.ini
run echo "zend_loader.enable=1" >> /usr/local/php5/php.ini
run ln -s /usr/local/php5/bin/* /usr/local/bin
run ln -s /usr/local/php5/sbin/* /usr/local/sbin
add test.php /usr/local/httpd/htdocs/
add index.php /usr/local/httpd/htdocs/
run echo "LoadModule php5_module modules/libphp5.so" >> /usr/local/httpd/conf/httpd.conf
run echo "AddType application/x-httpd-php .php" >> /usr/local/httpd/conf/httpd.conf
run echo "DirectoryIndex index.php index.html" >> /usr/local/httpd/conf/httpd.conf
add yx.sh /yx.sh
expose 9000
cmd ["/yx.sh"]
第三步 编写网页执行文件
vim test.php
<?php
phpinfo();
?>
vim index.php
<?php
phpinfo();
?>
第四步 编写启动脚本
vim yx.sh
#!/bin/bash
/usr/local/httpd/bin/httpd
/usr/local/mysql/bin/mysqld_safe
/usr/local/php5/sbin/php-fpm
第五步 赋权并且构建镜像
chmod 777 yx.sh
docker build -t centos7:lamp /root/dockerfile/lamp/
第六步 检查镜像
docker images | grep lamp
第七步 创建容器
docker run -d -it --name lamp -p 8005:80 【 】
docker ps | grep lamp