Docker 安装 php 主要有 2 种方法,分别是直接通过 docker 命令安装或通过 Dockerfile 构建。php 相关的 docker 镜像所有版本可以查看镜像库的 php tags,官方地址为 https://hub.docker.com/_/php?tab=tags。
方式一:docker pull php
关键字搜索相关镜像
首先通过 php 关键字查询当前镜像库的所有 php 相关的镜像,使用 docker search 命令,具体示例如下:
knowledgedict@Mac ~ $ docker search php
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
php While designed for web development, the PH... 5403 [OK]
phpmyadmin/phpmyadmin A web interface for MySQL and MariaDB. 1055 [OK]
adminer Database management in a single PHP file. 434 [OK]
php-zendserver Zend Server - the integrated PHP applicati... 185 [OK]
webdevops/php-nginx Nginx with PHP-FPM 167 [OK]
webdevops/php-apache-dev PHP with Apache for Development (eg. with ... 126 [OK]
webdevops/php-apache Apache with PHP-FPM (based on webdevops/php) 106 [OK]
bitnami/php-fpm Bitnami PHP-FPM Docker Image 102 [OK]
phpunit/phpunit PHPUnit is a programmer-oriented testing f... 78 [OK]
nazarpc/phpmyadmin phpMyAdmin as Docker container, based on o... 61 [OK]
circleci/php CircleCI images for PHP 32
thecodingmachine/php General-purpose ultra-configurable PHP images 31 [OK]
phpipam/phpipam-www phpIPAM is an open-source web IP address m... 29
bitnami/phpmyadmin Bitnami Docker Image for phpMyAdmin 20 [OK]
phpdockerio/php72-fpm PHP 7.2 FPM base container for PHPDocker.io. 20 [OK]
adrianharabula/php7-with-oci8 Latest PHP 7.1 with apache and Oracle oci8 19 [OK]
bitnami/phpbb Bitnami Docker Image for phpBB 16 [OK]
phpdockerio/php7-fpm PHP 7 FPM base container for PHPDocker.io. 15 [OK]
arm32v7/php While designed for web development, the PH... 14
appsvc/php Azure App Service php dockerfiles 13 [OK]
phpdockerio/php73-fpm PHP 7.3 FPM base container for PHPDocker.io. 12
graze/php-alpine Smallish php7 alpine image with some commo... 12 [OK]
phpdockerio/php72-cli PHP 7.2 CLI base container for PHPDocker.io. 4 [OK]
phpdockerio/php7-cli PHP 7 CLI base container image for PHPDock... 1 [OK]
isotopab/php Docker PHP 1 [OK]
拉取指定版本的镜像
从镜像库拉取镜像用 docker pull 命令。
knowledgedict@Mac ~ $ docker pull php:zts-alpine3.12
zts-alpine3.12: Pulling from library/php
df20fa9351a1: Pull complete
b358d6dbbdff: Pull complete
0232d962484c: Pull complete
0c1d3ac04d2a: Pull complete
13a1a3f64247: Pull complete
6f346c585870: Pull complete
44a386adb02d: Pull complete
91777ee01b60: Pull complete
06340771d918: Pull complete
Digest: sha256:1615f55f74fa81fb0d1adf52fa6c03ece12aa7eff53040689b33ee99301e9a61
Status: Downloaded newer image for php:zts-alpine3.12
下载完成后,可以在本地的镜像列表查看相关信息,如下:
knowledgedict@Mac ~ $ docker images php
REPOSITORY TAG IMAGE ID CREATED SIZE
php zts-alpine3.12 38551aa61a27 37 hours ago 65.2 MB
运行容器
运行容器使用 docker run 命令,具体如下:
knowledgedict@Mac ~ $ docker run -itd --name php-demo -p 9000:9000 php:zts-alpine3.12
78421b0ee0b9030dbc2837ac1648997c510b25060c2457217de381aafaf55c11
启动后,查看相应容器运行信息:
knowledgedict@Mac ~ $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
78421b0ee0b9 php:zts-alpine3.12 "docker-php-entryp..." 47 minutes ago Up 24 seconds 0.0.0.0:9000->9000/tcp php-demo