docker 构建nginx + php
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker 构建nginx + php相关的知识,希望对你有一定的参考价值。
1、先pull镜像:
docker pull php:7.2.3-fpm
docker pull nginx:1.13
2、运行php镜像,/opt/app 存放代码:
docker run --name phpfpm -d -v /opt/app:/app php:5.6-fpm
3、运行nginx容器:
docker run --name nginx_server -d -p 80:80 --link phpfpm:phpfpm -v /opt/nginx/nginx.conf:/etc/nginx/nginx.conf --volumes-from phpfpm nginx
--link 将两个容器连接在一起
--volumes-from 将phpfpm挂载的代码也挂载到nginx上
nginx关于php的配置如下:
location ~ .php$ {
root /www;
fastcgi_pass phpfpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /app$fastcgi_script_name;
include fastcgi_params;
}
在nginx容器中,查看环境变量:
[email protected]:/# env
PHPFPM_NAME=/nginx_server/phpfpm
HOSTNAME=8e3fae96d9fc
PHPFPM_ENV_PHPIZE_DEPS=autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c
NJS_VERSION=1.13.9.0.1.15-1~stretch
PHPFPM_PORT_9000_TCP_PROTO=tcp
PHPFPM_ENV_PHP_INI_DIR=/usr/local/etc/php
NGINX_VERSION=1.13.9-1~stretch
PHPFPM_ENV_PHP_URL=https://secure.php.net/get/php-7.2.3.tar.xz/from/this/mirror
PHPFPM_ENV_PHP_LDFLAGS=-Wl,-O1 -Wl,--hash-style=both -pie
PWD=/
HOME=/root
PHPFPM_ENV_PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2
PHPFPM_PORT_9000_TCP_ADDR=172.17.0.3
PHPFPM_PORT=tcp://172.17.0.3:9000
PHPFPM_ENV_PHP_MD5=
PHPFPM_PORT_9000_TCP=tcp://172.17.0.3:9000
TERM=xterm
PHPFPM_ENV_PHP_VERSION=7.2.3
SHLVL=1
PHPFPM_ENV_PHP_SHA256=b3a94f1b562f413c0b96f54bc309706d83b29ac65d9b172bc7ed9fb40a5e651f
PHPFPM_PORT_9000_TCP_PORT=9000
PHPFPM_ENV_PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PHPFPM_ENV_GPG_KEYS=1729F83938DA44E27BA0F4D3DBDB397470D12172 B1B44D8F021E4E2D6021E995DC9FF8D3EE5AF27F
PHPFPM_ENV_PHP_EXTRA_CONFIGURE_ARGS=--enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data
PHPFPM_ENV_PHP_ASC_URL=https://secure.php.net/get/php-7.2.3.tar.xz.asc/from/this/mirror
_=/usr/bin/env
以上是关于docker 构建nginx + php的主要内容,如果未能解决你的问题,请参考以下文章
如何为多个PHP-FPM容器构建单一的Nginx Docker镜像
Win7系统下,docker构建nginx+php7环境实践