简单几步就教会你如何使用 dockerfile 制作 LNMP 镜像,还不赶紧学起来
简单几步就教会你如何使用dockerfile制作LNMP镜像前言一、dockerfile撰写php镜像二、dockerfile撰写mysql镜像三、dockerfile撰写nginx镜像四、查看镜像构建情况五、分别开启nginx、mysql和php镜像六、进行测试前言注意:搞docker的环境时,切记把firewalld和selinux关了,否则docker很多服务会起不来一、dockerfile
·
简单几步就教会你如何使用dockerfile制作LNMP镜像
前言
注意:搞docker的环境时,切记把firewalld和selinux关了,否则docker很多服务会起不来
一、dockerfile撰写php镜像
FROM centos:7.4.1708
ENV TIME_ZOME Asia/Shanghai
ARG WJ="php-7.1.10"
ADD $WJ.tar.bz2 /opt
RUN yum -y install gcc gcc-c++ make gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel bison \
&& mkdir -p /usr/local/php/etc \
&& cd /opt/$WJ \
&& ./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-gd --with-mysqli \
--with-openssl --with-zlib --with-curl \
--with-jpeg-dir --with-png-dir --with-iconv \
--enable-fpm --enable-zip --enable-mbstring \
&& make -j 2 \
&& make install \
&& cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf \
&& cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf \
&& sed -i '/;daemonize/a\daemonize = no' /usr/local/php/etc/php-fpm.conf \
&& sed -i 's/127.0.0.1/0.0.0.0/g' /usr/local/php/etc/php-fpm.d/www.conf \
&& echo "${TIME_ZOME}" > /etc/timezone \
&& ln -sf /usr/share/zoneinfo/${TIME_ZOME} /etc/localtime \
&& rm -rf /opt/local/php* \
&& yum clean all \
&& yum -y remove gcc gcc-c++ make \
&& mkdir -p /usr/local/nginx/html \
&& echo -e "<?php\nphpinfo();\n?>" > /usr/local/nginx/html/index.php
WORKDIR /usr/local/php/
EXPOSE 9000
CMD ["sbin/php-fpm","-c","etc/php-fpm.conf"]
文件结构:
创建php镜像:
二、dockerfile撰写mysql镜像
FROM centos:7.4.1708
ADD mysql-5.6.26.tar.gz /opt
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo \
&& useradd -s /sbin/nologin mysql \
&& yum -y install gcc gcc-c++ make pcre-devel expat-devel perl ncurses-devel autoconf cmake \
&& cd /opt/mysql-5.6.26/ \
&& cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DSYSCONFIDIR=/etc -DMYSQL_DATADIR=/home/mysql/ -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock \
&& make -j2 \
&& make install \
&& cp -f support-files/my-default.cnf /etc/my.cnf \
&& cp support-files/mysql.server /etc/init.d/mysqld \
&& chown -R mysql:mysql /usr/local/mysql/ \
&& sed -i 's/^basedir/basedir=\/usr\/local\/mysql/g' /etc/init.d/mysqld \
&& sed -i 's/^datadir/datadir=\/home\/mysql/g' /etc/init.d/mysqld \
&& /usr/local/mysql/scripts/mysql_install_db --user=mysql --ldata=/var/lib/mysql --basedir=/usr/local/mysql --datadir=/home/mysql
ENV PATH /usr/local/mysql/bin:$PATH
EXPOSE 3306
ENTRYPOINT ["/usr/local/mysql/bin/mysqld_safe"]
文件结构:
创建mysql镜像:
三、dockerfile撰写nginx镜像
FROM centos:7.4.1708
ADD nginx-1.12.0.tar.gz /opt
RUN yum -y install pcre-devel zlib-devel openssl-devel gcc gcc-c++ make \
&& useradd -M -s /sbin/nologin nginx \
&& cd /opt/nginx-1.12.0/ \
&& ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-file-aio --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module \
&& make \
&& make install \
&& ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx \
&& echo -e "events {\nuse epoll;\nworker_connections 1024;\n}\nhttp {\nserver_tokens on;\nserver {\nlisten 80;\nserver_name localhost;\nlocation / {\nroot html;\nindex index.html index.htmi index.php;\n}\nerror_page 500 502 503 504 /50x.html;\nlocation = /50x.html {\nroot html;\n}\nlocation ~ \.php$ {\nroot html;\nfastcgi_pass 172.168.184.30:9000;\nfastcgi_index index.php;\nfastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;\ninclude fastcgi_params;\n}\n}\n}" > /usr/local/nginx/conf/nginx.conf
ENV PATH /usr/local/nginx/sbin:$PATH
WORKDIR /usr/local/nginx/
EXPOSE 80
CMD ["nginx","-g","daemon off;"]
文件结构:
创建mysql镜像:
四、查看镜像构建情况
五、分别开启nginx、mysql和php镜像
六、进行测试
更多推荐
已为社区贡献1条内容
所有评论(0)