visualbox 虛擬機 CentOS 7.6 ip: 192.168.1.187php
本機已安裝 nginx : nginx version: nginx/1.12.2 php : PHP 7.2.16 (cli) (built: Mar 10 2019 21:22:49) ( NTS )html
Alpine 操做系統是一個面向安全的輕型 Linux 發行版mysql
alpine linux官網 https://www.alpinelinux.org/ 簡介 https://blog.csdn.net/bbwangj/article/details/81088231linux
建立 Dockerfile 在本身的 dockerfile 目錄下,新建一個 Alpine mkdir Alpine cd Alpine touch Dockerfile vim Dockerfile 如下內容:nginx
FROM php:5.6.37-fpm-alpine3.7 RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ && apk update\ && apk add --no-cache libmcrypt-dev freetype-dev libjpeg-turbo-dev \ git \ # libfreetype6-dev \ # libjpeg62-turbo-dev \ libpng-dev \ && docker-php-ext-install mcrypt mysqli pdo pdo_mysql mbstring bcmath zip opcache\ && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/ \ && docker-php-ext-install -j$(nproc) gd
生成鏡像 docker build -t myphp5606:v1 .git
最終成功的結果應該是這樣的 ..... OK: 34 MiB in 42 packages Removing intermediate container d09f8e2e89d8 ---> fd888a483d00 Successfully built fd888a483d00 Successfully tagged myphp5606:v1sql
docker imagesdocker
REPOSITORY TAG IMAGE ID CREATED SIZE myphp5606 v1 fd888a483d00 About an hour ago 77.4MB ...
生成一個 php 容器 ** 由於學習過程當中鏡像和容器都已經比較多,先找個能用的容器名字和映射端口 ss -tlnp |grep 9002 確認沒有佔用!vim
sudo docker run -p 9002:9000 --name myphp5606 -v /usr/share/nginx/html:/usr/share/nginx/html -d myphp5606:v1
進入容器查看 docker exec -it myphp5606 shcentos
php -v 返回結果: PHP 5.6.37 (cli) (built: Sep 12 2018 04:00:31) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
php -m 返回結果: [PHP Modules] bcmath Core ctype curl ...
php -m |grep gd 返回結果: gd
打開 nginx 網站測試 修改 php 配置 9000 端口是本機的 php ,版本是 7.2 9002 端口是剛纔安裝的 docker PHP,版本是 5.6
vim nginx.conf
# fastcgi_pass 127.0.0.1:9000; fastcgi_pass 127.0.0.1:9002;
curl 127.0.0.1/index.php