├── .gitignore
├── README.md
├── app
└── www
│ ├── README.md
│ ├── index.html
│ └── phpinfo.php
├── docker-compose-dev.yml
├── docker-compose.yml
├── docker-sync.yml
├── example.env
└── services
├── console
├── Dockerfile
└── composer-1.1.3.phar
├── nginx
├── Dockerfile
└── config
│ └── default.conf
└── php
├── Dockerfile
└── config
├── opcache-recommended.ini
└── php.ini
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled source #
2 | ###################
3 | *.com
4 | *.class
5 | *.dll
6 | *.exe
7 | *.o
8 | *.so
9 |
10 | # Packages #
11 | ############
12 | # it's better to unpack these files and commit the raw source
13 | # git has its own built in compression methods
14 | *.7z
15 | *.dmg
16 | *.gz
17 | *.iso
18 | *.jar
19 | *.rar
20 | *.tar
21 | *.zip
22 |
23 | # Logs and databases #
24 | ######################
25 | *.log
26 | *.sql
27 | *.sqlite
28 |
29 | # OS generated files #
30 | ######################
31 | .DS_Store
32 | .DS_Store?
33 | ._*
34 | .Spotlight-V100
35 | .Trashes
36 | ehthumbs.db
37 | Thumbs.db
38 |
39 | # Node specific #
40 | #################
41 | lib-cov
42 | *.seed
43 | *.log
44 | *.dat
45 | *.out
46 | *.pid
47 | *.gz
48 | pids
49 | logs
50 | #results
51 | npm-debug.log
52 | node_modules/
53 |
54 | # Bower #
55 | #################
56 | bower_components/
57 |
58 | # Project #
59 | app/database/
60 | .env
61 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # nest
2 |
3 | nest 是一个用 Docker 搭建的本地 PHP 应用开发与运行环境。
4 |
5 | ## 准备
6 |
7 | 安装 Docker for Windows 或 Docker for Mac。
8 |
9 | ## 服务
10 |
11 | * db:使用 mariadb 作为应用的数据库
12 | * php:解释 php 脚本,使用 php-fpm
13 | * web:使用 NGINX 作为应用的 web 服务器
14 | * console:常用工具
15 | * phpmyadmin:管理数据库的 web 界面
16 |
17 | ## 结构
18 |
19 | * app:这个目录存储应用,database 放数据库,web 放应用的代码。
20 | * services: 环境里定义的服务需要的一些资源,比如 nginx 的配置文件在 nginx/config/default.conf 。
21 | * docker-compose-dev.yml:定义本地开发环境需要的服务。
22 | * docker-compose.yml:生产环境需要的服务,暂时为空白。
23 | * docker-sync.yml:同步文件用的配置文件。
24 | * example.env:环境文件示例,复制一份这个文件,把复制的文件命名为 .env 。
25 |
26 | ## 使用
27 |
28 | 准备:
29 |
30 | ```
31 | git clone https://github.com/ninghao/nest.git
32 | cd nest
33 | cp example.env .env
34 | ```
35 |
36 | 基本用法:
37 |
38 | ```
39 | docker-compose up -d
40 | ```
41 |
42 | 同步文件:
43 |
44 | ```
45 | docker-sync start
46 | docker-compose up -d
47 | ```
48 |
49 | 或:
50 |
51 | ```
52 | docker-sync-stack start
53 | ```
54 |
--------------------------------------------------------------------------------
/app/www/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ninghao/nest/d608a27b08c6a701f5dcae765bc236a7057eceb3/app/www/README.md
--------------------------------------------------------------------------------
/app/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | hello
5 |
6 |
35 |
36 |
37 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/www/phpinfo.php:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/docker-compose-dev.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 | console:
4 | image: registry.cn-hangzhou.aliyuncs.com/ninghao/console
5 | volumes:
6 | - ninghao-unison-sync:/mnt/app/www:nocopy
7 | tty: true
8 | web:
9 | image: registry.cn-hangzhou.aliyuncs.com/ninghao/nginx
10 | ports:
11 | - "8080:80"
12 | depends_on:
13 | - php
14 | volumes:
15 | - ninghao-unison-sync:/mnt/app/www:nocopy
16 | - ./services/nginx/config:/etc/nginx/conf.d
17 | php:
18 | image: registry.cn-hangzhou.aliyuncs.com/ninghao/php
19 | volumes:
20 | - ninghao-unison-sync:/mnt/app/www:nocopy
21 | db:
22 | image: mariadb:10.1
23 | environment:
24 | MYSQL_ROOT_PASSWORD: "root"
25 | MYSQL_DATABASE: "app"
26 | MYSQL_USER: "app"
27 | MYSQL_PASSWORD: "123123"
28 | volumes:
29 | - ./app/database:/var/lib/mysql
30 | phpmyadmin:
31 | image: phpmyadmin/phpmyadmin
32 | ports:
33 | - "8081:80"
34 | environment:
35 | PMA_HOST: "db"
36 | PMA_USER: "app"
37 | PMA_PASSWORD: "123123"
38 | volumes:
39 | ninghao-unison-sync:
40 | external: true
41 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
--------------------------------------------------------------------------------
/docker-sync.yml:
--------------------------------------------------------------------------------
1 | version: '2'
2 | options:
3 | verbose: true
4 | unison_image: 'eugenmayer/unison'
5 | cli_mode: 'auto'
6 | compose-file-path: 'docker-compose.yml'
7 | compose-dev-file-path: 'docker-compose-dev.yml'
8 | syncs:
9 | ninghao-unison-sync:
10 | src: './app/www'
11 | sync_prefer: 'default'
12 | sync_userid: '33'
13 | sync_strategy: 'unison'
14 | sync_excludes: [
15 | '.gitignore',
16 | '.git/',
17 | '.DS_Store',
18 | ]
19 |
--------------------------------------------------------------------------------
/example.env:
--------------------------------------------------------------------------------
1 | COMPOSE_FILE=docker-compose-dev.yml
2 |
--------------------------------------------------------------------------------
/services/console/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM php:7.0
2 | MAINTAINER wanghao
3 |
4 | WORKDIR /mnt/app
5 |
6 | # 常用工具
7 | RUN apt-get update && apt-get install -y git curl wget cron vim locales libfreetype6-dev mariadb-client \
8 | && rm -rf /var/lib/apt/lists/* \
9 | && pecl install zip \
10 | && docker-php-ext-enable zip \
11 | && docker-php-ext-install mysqli pdo_mysql gd bcmath
12 |
13 | ENV PHPREDIS_VERSION 3.0.0
14 |
15 | RUN mkdir -p /usr/src/php/ext/redis \
16 | && curl -L https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 \
17 | && echo 'redis' >> /usr/src/php-available-exts \
18 | && docker-php-ext-install redis
19 |
20 | RUN echo "PS1='[console]# '" >> /root/.bashrc
21 |
22 | # 把语言设置成简体中文
23 | RUN dpkg-reconfigure locales && \
24 | locale-gen C.UTF-8 && \
25 | /usr/sbin/update-locale LANG=C.UTF-8
26 | RUN echo 'zh_CN.UTF-8 UTF-8' >> /etc/locale.gen && \
27 | locale-gen
28 | ENV LC_ALL C.UTF-8
29 | ENV LANG zh_CN.UTF-8
30 | ENV LANGUAGE zh_CN.UTF-8
31 |
32 | # 配置 git
33 | # RUN git config --global user.name "wanghao8080" \
34 | # && git config --global user.email "117663444@qq.com"
35 |
36 | # 安装与配置 composer
37 | # Composer 官方安装脚本 https://getcomposer.org/download/
38 | # 因为在国内下载 composer 太慢,我们直接把下载下来的 composer 复制到容器里使用。
39 | COPY ./files/composer-1.1.3.phar /usr/local/bin/composer
40 | RUN chmod +x /usr/local/bin/composer
41 | RUN echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc \
42 | && . ~/.bashrc \
43 | && composer config -g repo.packagist composer https://packagist.phpcomposer.com
44 |
45 | # 安装管理 WordPress 项目的 wp-cli
46 | RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
47 | && chmod +x wp-cli.phar \
48 | && mv wp-cli.phar /usr/local/bin/wp
49 |
50 | # 安装管理 Drupal 项目的 drush
51 | RUN php -r "readfile('http://files.drush.org/drush.phar');" > drush \
52 | && chmod +x drush \
53 | && mv drush /usr/local/bin
54 |
55 | # 安装管理 Drupal 项目的 Drupal Console
56 | RUN php -r "readfile('https://drupalconsole.com/installer');" > drupal \
57 | && chmod +x drupal \
58 | && mv drupal /usr/local/bin \
59 | && drupal self-update
60 |
--------------------------------------------------------------------------------
/services/console/composer-1.1.3.phar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ninghao/nest/d608a27b08c6a701f5dcae765bc236a7057eceb3/services/console/composer-1.1.3.phar
--------------------------------------------------------------------------------
/services/nginx/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM centos:7
2 | MAINTAINER wanghao
3 |
4 | # 安装必备工具
5 | RUN yum install wget curl perl gcc pcre-devel zlib-devel make -y
6 |
7 | # 进入工作目录
8 | WORKDIR /usr/local/src
9 |
10 | # 下载 openssl 源
11 | RUN curl -L --progress https://www.openssl.org/source/openssl-1.0.2-latest.tar.gz | tar xz
12 | RUN mv openssl*/ openssl/
13 |
14 | # 下载 nginx 源
15 | RUN curl -L --progress http://nginx.org/download/nginx-1.11.10.tar.gz | tar xz
16 | RUN mv nginx*/ nginx/
17 |
18 | # 编译 nginx
19 | WORKDIR /usr/local/src/nginx
20 | RUN ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-stream_realip_module --with-openssl=/usr/local/src/openssl \
21 | && make \
22 | && make install \
23 | && useradd nginx \
24 | && mkdir /etc/nginx/conf.d \
25 | && mkdir /var/cache/nginx \
26 | && chown nginx:root /var/cache/nginx \
27 | && rm -rf /usr/local/src/nginx \
28 | && rm -rf /usr/local/src/openssl \
29 | && rm -rf /var/cache/yum
30 |
31 | # 复制准备好的配置文件
32 | COPY ./config/nginx.conf /etc/nginx/
33 | COPY ./config/default.conf /etc/nginx/conf.d/
34 |
35 | # forward request and error logs to docker log collector
36 | RUN touch /var/log/nginx/access.log \
37 | && touch /var/log/nginx/error.log \
38 | && ln -sf /dev/stdout /var/log/nginx/access.log \
39 | && ln -sf /dev/stderr /var/log/nginx/error.log
40 |
41 | EXPOSE 80 443
42 |
43 | CMD ["nginx", "-g", "daemon off;"]
44 |
--------------------------------------------------------------------------------
/services/nginx/config/default.conf:
--------------------------------------------------------------------------------
1 | server {
2 | listen 80;
3 | server_name localhost;
4 | root /mnt/app/www;
5 | index index.php index.html index.htm;
6 | client_max_body_size 256m;
7 |
8 | location / {
9 | try_files $uri $uri/ /index.php?$query_string;
10 | }
11 |
12 | location ~ \.php$ {
13 | fastcgi_pass php:9000;
14 | fastcgi_index index.php;
15 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
16 | include fastcgi_params;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/services/php/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM php:7.0.9-fpm
2 | MAINTAINER wanghao
3 |
4 | ENV PHPREDIS_VERSION 3.0.0
5 |
6 | RUN mkdir -p /usr/src/php/ext/redis \
7 | && curl -L https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 \
8 | && echo 'redis' >> /usr/src/php-available-exts \
9 | && docker-php-ext-install redis
10 |
11 | RUN apt-get update && apt-get install -y libpng12-dev libjpeg-dev \
12 | && rm -rf /var/lib/apt/lists/* \
13 | && pecl install zip \
14 | && docker-php-ext-enable zip \
15 | && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
16 | && docker-php-ext-install gd mysqli pdo_mysql zip opcache redis bcmath
17 |
18 | COPY ./config/php.ini /usr/local/etc/php/conf.d/
19 | COPY ./config/opcache-recommended.ini /usr/local/etc/php/conf.d/
20 |
--------------------------------------------------------------------------------
/services/php/config/opcache-recommended.ini:
--------------------------------------------------------------------------------
1 | opcache.memory_consumption=128
2 | opcache.interned_strings_buffer=8
3 | opcache.max_accelerated_files=4000
4 | opcache.revalidate_freq=60
5 | opcache.fast_shutdown=1
6 | opcache.enable_cli=1
7 | opcache.enable=0
8 |
--------------------------------------------------------------------------------
/services/php/config/php.ini:
--------------------------------------------------------------------------------
1 | memory_limit = 256M
2 | post_max_size = 100M
3 | upload_max_filesize = 100M
4 |
--------------------------------------------------------------------------------