Dockerfile 创建
FROM php:fpm-alpine
MAINTAINER amor
# 更新源
# ENV PHPREDIS_VERSION="3.1.4"
# ENV PHPMECCACHED_VERSION="2.2.0"
# ENV PHPXDEBUG_VERSION="2.5.5"
# php 核心库
# docker-php 支持的扩展
# bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mcrypt mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zip
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
&& apk update \
&& apk add --update --no-cache \
freetype-dev \
libjpeg-turbo-dev \
libmcrypt-dev \
libpng-dev \
postgresql-dev \
curl-dev \
# memcached
# libmemcached-dev \
# zlib-dev \
&& docker-php-ext-install -j"$(getconf _NPROCESSORS_ONLN)" iconv mcrypt mysqli pdo pdo_mysql pdo_pgsql curl zip \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j"$(getconf _NPROCESSORS_ONLN)" gd \
&& echo 'pdo_mysql.default_socket=/run/mysqld/mysqld.sock' >> /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini
# && pecl install redis-"$PHPREDIS_VERSION" \
# && pecl install xdebug-"$PHPXDEBUG_VERSION" \
# && docker-php-ext-enable redis xdebug \
# && pecl install memcached-"$PHPMECCACHED_VERSION" \
# && docker-php-ext-enable memcached
# 复制php.ini文件到php容器配置目录
COPY ./conf/php-fpm/php.ini /usr/local/etc/php/
CMD ["php-fpm"]
注意事项:php.ini 建议做到版本对应
docker-compose.yml 创建
php-fpm:
build: .
expose:
- "9000"
volumes:
- /data/nutcloud/ubuntu/website/:/var/www/html/
links:
- mysql:mysql
- redis:redis
mysql:
image: mysql:latest
ports:
- "3306:3306"
volumes:
# sql镜像数据目录
- ./mysql/:/var/lib/mysql/:rw
environment:
MYSQL_DATABASE: test
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
redis:
image: redis:alpine
ports:
- "6379:6379"
nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- /data/nutcloud/ubuntu/website/:/var/www/html/
- ./conf/nginx/conf.d:/etc/nginx/conf.d/:ro
- ./log/nginx/:/var/log/nginx/:rw
links:
- php-fpm:fpm
注意事项:
代码挂载有两种方式:
第一种:在Dockerfile中直接将本地代码COPY到容器中,但是不方便调试,适合部署时使用。
第二种:通过数据卷挂载到容器如没有能力或者不知道配置文件各项参数,请尽可能少的加载自己的配置文件。
注意目录对应
数据库连接时请使用links配置项中的mysql名称
composer,bower,git请安装到本地
nginx配置文件(含pathinfo)
server {
listen 80;
server_name website.fastadminamor.com;
#charset koi8-r;
access_log /var/log/nginx/website.access.log main;
error_log /var/log/nginx/website.error.log;
location / {
root /var/www/html/fastadmin/public;
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?s=$1 last;
break;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html/fastadmin/public;
fastcgi_pass fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
#location ~ ^.+.php {
# fastcgi_pass fpm:9000;
# fastcgi_index index.php;
# include fastcgi_params;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
目录结构(请自行创建)
.
├── conf
│ ├── nginx
│ │ ├── conf.d
│ │ │ └── website.fastadmin.com.conf
│ └── php-fpm
│ └── php.ini
├── docker-compose.yml
├── Dockerfile
├── log
│ ├── nginx
│ │ ├── access.log
│ │ ├── error.log
│ │ ├── website.access.log
│ │ └── website.error.log
├── mysql
phpstorm配置Docker
配置docker
下载安装docker做如下配置
配置php-cli
测试:
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。