* Added PHP dockerfile.

* Refactored dockerfile to use multistage build. Reduced layer count from 22 to 8.

* Move to samples folder. Update readme
This commit is contained in:
Sourabh Shirhatti 2018-01-22 11:50:59 -08:00 коммит произвёл GitHub
Родитель 3404db86e4
Коммит c77ec3d9e5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 101 добавлений и 0 удалений

62
samples/php/Dockerfile Normal file
Просмотреть файл

@ -0,0 +1,62 @@
# escape=`
#
# This Dockerfile is provided for demonstration purposes only and it is not supported by Microsoft
# PHP 7.1 x64 running on IIS
#
FROM microsoft/iis AS php71
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
RUN `
try { `
# Install PHP `
Invoke-WebRequest 'https://sourceforge.net/projects/phpinstallermsi/files/zip/php-7.1.7-nts-Win32-VC14-x64.zip/download' -UserAgent '' -OutFile C:\php.zip; `
Invoke-WebRequest 'https://download.microsoft.com/download/6/A/A/6AA4EDFF-645B-48C5-81CC-ED5963AEAD48/vc_redist.x64.exe' -UserAgent '' -OutFile C:\vc_redist-x64.exe; `
Invoke-WebRequest 'https://sourceforge.net/projects/wincache/files/wincache-2.0.0/wincachewpi-2.0.0.8-7.1-nts-vc14-x64.exe/download' -UserAgent '' -OutFile C:\php_wincache.exe; `
Expand-Archive -Path c:\php.zip -DestinationPath C:\PHP; `
`
# Install PHP Win Cache `
C:\php_wincache.exe /Q /C "/T:C:\php_wincache_msi"; `
Start-Process -FilePath msiexec -ArgumentList '/a C:\php_wincache_msi\wincache71x64wpi.msi /qb TARGETDIR=C:\php_wincache_msi\extracted' -NoNewWindow -PassThru -Wait; `
Copy-Item C:\php_wincache_msi\extracted\PFiles\php_wincache.dll c:\PHP\ext; `
`
# Configure PHP `
Copy-Item C:\PHP\php.ini-production C:\PHP\php.ini; `
} `
catch { `
$_.Exception; `
$_; `
exit 1; `
}
FROM microsoft/iis
COPY --from=php71 ["/php/", "/php/"]
COPY --from=php71 ["/vc_redist-x64.exe", "/vc_redist-x64.exe"]
#
# Enable required IIS Features
# Install VC Redist 14
# Configure IIS
# Configure system PATH
#
RUN dism.exe /Online /Enable-Feature /FeatureName:IIS-CGI /All && `
C:\vc_redist-x64.exe /quiet /install && `
del C:\vc_redist-x64.exe && `
%windir%\system32\inetsrv\appcmd.exe set config /section:system.webServer/fastCgi /+[fullPath='c:\PHP\php-cgi.exe'] && `
%windir%\system32\inetsrv\appcmd.exe set config /section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='c:\PHP\php-cgi.exe',resourceType='Either'] && `
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /[fullPath='c:\PHP\php-cgi.exe'].instanceMaxRequests:10000 && `
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+[fullPath='c:\PHP\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='10000'] && `
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+[fullPath='c:\PHP\php-cgi.exe'].environmentVariables.[name='PHPRC',value='C:\PHP'] && `
%windir%\system32\inetsrv\appcmd.exe set config /section:defaultDocument /enabled:true /+files.[value='index.php'] && `
setx PATH /M %PATH%;C:\PHP && `
setx PHP /M "C:\PHP" && `
del C:\inetpub\wwwroot\* /Q
# Optional: Add a starter page
# RUN powershell.exe -Command '<?php phpinfo(); ?>' | Out-File C:\inetpub\wwwroot\index.php -Encoding UTF8
#
#ADD any application content and perform any configuration below

39
samples/php/README.md Normal file
Просмотреть файл

@ -0,0 +1,39 @@
# PHP On IIS
## What is PHP
PHP (PHP: Hypertext Processor) is a server side scripting language as well as web framework that can be used to develop applications ranging from simple to complex.
## Getting Started
To add a PHP application into the container, first put the application content into a folder named _content_ and then append the following commands to the dockerfile located within this directory
```Dockerfile
# PHP dockerfile
# The content of the docker file will be here
# Add your content below
WORKDIR /inetpub/wwwroot
COPY ./content .
```
You can then build the image:
```
docker build -t iis-php .
docker run -d -p 80:00 --name my-php-site iis-php
```
## Testing PHP
To test the PHP functionality of the container without the need for a PHP application uncomment the following _RUN_ line within the docker file
```
# Optional: Add a starter page
# RUN powershell.exe -Command "'<?php phpinfo(); ?>' | Out-File C:\inetpub\wwwroot\phpinfo.php" -Encoding UTF8
```
Once the container is running, navigate to http://\<container host name\>/phpinfo.php
The generic php info page should be returned from the container. This verifies that PHP is functioning as expected.