跳到主要内容

二十三、Docker 部署 PHP 环境

PHP是当下最流行的 Web 服务器端开发语言,号称 地球上最好的语言,没有之一。Docker 部署 PHP 环境有两种方式: 通过 Dockerfile 构建 和 从 Docker 仓库拉取

我们以当前最新的版本 7.2.6 安装为例

1. 使用 docker pull php

这是最简单的方式,开箱即用

1、 使用dockersearchphp命令可以列出docker.io上所有的PHP有关的镜像;

    [root@pottercoding.cn ~]# docker search php
NAME DESCRIPTION OFFICIAL
php While designed for web... [OK]
...
有很多版本,我们选择官方的 php

2、 拉取最新的PHP标签:7.2.6-fpm-stretch

    [root@pottercoding.cn ~]# docker pull php:7.2.6-fpm-stretch

3、 稍等片刻,下载完成后,就可以在本地镜像列表里找到REPOSITORY为php,标签为7.2.6-fpm-stretch的镜像;

    [root@pottercoding.cn ~]# docker images php
REPOSITORY TAG IMAGE ID ... SIZE
php 7.2.6-fpm-stretch 0a757334c1f6 ... 367.7 MB

2. 通过 Dockerfile 文件构建

使用Dockerfile 文件构建,我们可以实现定制,并且熟悉 PHP 的安装过程

1、 创建目录php,用于存放后面的相关东西;

    [root@pottercoding.cn ~]# mkdir -p php/logs php/conf
<table> 
<thead>
<tr>
<th align="left">文件</th>
<th align="left">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">logs</td>
<td align="left">该目录将映射为 phpops 容器的日志目录</td>
</tr>
<tr>
<td align="left">conf</td>
<td align="left">该目录里的配置文件将映射为 phpops 容器的配置文件</td>
</tr>
</tbody>
</table>