811 views
Liunx-服务安装

Dockerfile使用

文章目录

注:所有操作在同一个目录下进行,避免不必要的麻烦

Dockerfile语法链接:https://www.cnblogs.com/boshen-hzb/p/6400272.html

1、创建一个php测试页面

[code]

echo “<?php

phpinfo()

?>” > index.php

[/code]

2、创建一个dockerfile配置文件

命名必须为Dockerfile

[code]vim Dockerfile[/code]

3、写入内容

[code]

Dockerfile内容从此开始

From centos

MAINTAINER ying

安装依赖

RUN yum -y install httpd httpd-devel wget gcc perl epel-release

RUN yum -y install libxml2 \

libxml2-devel openssl openssl-devel bzip2 bzip2-devel \

libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel \

freetype freetype-devel gmp gmp-devel \

libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

下载安装PHP7

ADD http://cn2.php.net/distributions/php-7.1.1.tar.gz .

RUN tar -zxvf php-7.1.1.tar.gz

RUN mkdir -p /usr/local/php

RUN cd php-7.1.1&&./configure –prefix=/usr/local/php –with-config-file-path=/etc –enable-fpm –with-fpm-user=nginx –with-fpm-group=nginx –enable-inline-optimization –disable-debug –disable-rpath –enable-shared –enable-soap –with-apxs2=/usr/bin/apxs –with-libxml-dir –with-xmlrpc –with-openssl –with-mcrypt –with-mhash –with-pcre-regex –with-sqlite3 –with-zlib –enable-bcmath –with-iconv –with-bz2 –enable-calendar –with-curl –with-cdb –enable-dom –enable-exif –enable-fileinfo –enable-filter –with-pcre-dir –enable-ftp –with-gd –with-openssl-dir –with-jpeg-dir –with-png-dir –with-zlib-dir –with-freetype-dir –enable-gd-native-ttf –enable-gd-jis-conv –with-gettext –with-gmp –with-mhash –enable-json –enable-mbstring –enable-mbregex –enable-mbregex-backtrack –with-libmbfl –with-onig –enable-pdo –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-zlib-dir –with-pdo-sqlite –with-readline –enable-session –enable-shmop –enable-simplexml –enable-sockets –enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-wddx –with-libxml-dir –with-xsl –enable-zip –enable-mysqlnd-compression-support –with-pear –enable-opcache && make && make install && cp php.ini-production /etc/php.ini

修改配置文件

RUN sed -i ‘s# DirectoryIndex index.html# DirectoryIndex index.php index.html#g’ /etc/httpd/conf/httpd.conf

RUN sed -i ‘/ AddType application\/x-compress .Z/a\ AddType application\/x-httpd-php .php’ /etc/httpd/conf/httpd.conf

RUN sed -i ‘/www.example.com:80/a\ServerName www.example.com:80’ /etc/httpd/conf/httpd.conf

在本地创建一个php测试页面,然后复制到容器发布目录里

COPY index.php /var/www/html/index.php

暴露端口

EXPOSE 80 22

启动容器后执行的命令

ENTRYPOINT /usr/sbin/httpd && tail -f /etc/passwd

Dockerfile内容到此结束

[/code]

4、创建镜像:

docker build -t centos_lap .

docker  images //可以看到我们新建的镜像

docker run -itd -p 8088:80 centos_lap bash

进入容器或者直接访问测试即可

Leave a Reply

影子专属博客 赣ICP备17013143号