▶ 手动构建 yapi 镜像
1、启动 MongoDB
docker run -d --name mongo-yapi mongo
2、下载 YAPI 到本地
wget -o yapi.tar.gz https://github.com/YMFE/yapi/archive/v1.9.2.tar.gz
下载地址:https://github.com/YMFE/yapi/releases
3、编辑 Dockerfile
FROM node:12-alpine as builder
RUN apk add --no-cache git python make openssl tar gcc
COPY yapi-1.9.2.tar.gz /home
RUN cd /home && tar zxvf yapi-1.9.2.tar.gz && mkdir /api && mv /home/yapi-1.9.2 /api/vendors
RUN cd /api/vendors && \
npm install --production --registry https://registry.npm.taobao.org
FROM node:12-alpine
MAINTAINER nswlp@nslpw.cn
ENV TZ="Asia/Shanghai" HOME="/api/vendors"
WORKDIR ${HOME}
COPY --from=builder /api/vendors /api/vendors
COPY config.json /api/
EXPOSE 3000
ENTRYPOINT ["node"]自定义配置文件挂载到目录
/api/config.json,官方自定义配置文件 -> 项目根目录下的
config_example.json下面的是本示例中的配置
{
"port": "3000",
"adminAccount": "admin@admin.com",
"timeout":120000,
"db": {
"servername": "mongo",
"DATABASE": "yapis",
"port": 27017,
"user": "",
"pass": "",
"authSource": ""
},
"mail": {
"enable": true,
"host": "smtp.163.com",
"port": 465,
"from": "***@163.com",
"auth": {
"user": "***@163.com",
"pass": "*****"
}
}
}4、构建镜像
docker build -t yapi .
5、初始化 Yapi 数据库索引及管理员账号
docker run -it --rm \ --link mongo-yapi:mongo \ --entrypoint npm \ --workdir /api/vendors \ registry.cn-hangzhou.aliyuncs.com/anoy/yapi \ run install-server
6、启动 Yapi 服务
docker run -d \ --name yapi \ --link mongo-yapi:mongo \ --workdir /api/vendors \ -p 3000:3000 \ registry.cn-hangzhou.aliyuncs.com/anoy/yapi \ server/app.js
▶ 使用 Yapi
访问 http://localhost:3000 登录账号 admin@admin.com,密码 ymfe.org
至此,帅气的 Yapi 就可以轻松使用啦!更多文档信息,请参考
▶ 使用 第三方 Docker 构建 Yapi
1、获取 Yapi 镜像
docker pull registry.cn-hangzhou.aliyuncs.com/anoy/yapi
2、接着上面的第五步继续
▶ 其他相关操作
关闭 Yapi
docker stop yapi
启动 Yapi
docker start yapi
升级 Yapi
# 1、停止并删除旧版容器 docker rm -f yapi # 2、获取最新镜像 docker pull registry.cn-hangzhou.aliyuncs.com/anoy/yapi # 3、启动新容器 docker run -d \ --name yapi \ --link mongo-yapi:mongo \ --workdir /api/vendors \ -p 3000:3000 \ registry.cn-hangzhou.aliyuncs.com/anoy/yapi \ server/app.js
▶ 其他工具
PHP版MongoDB 管理工具: Rockmongo
RockMongo是PHP5写的一个MongoDB管理工具。
通过 Rockmongo 你可以管理 MongoDB服务,数据库,集合,文档,索引等等。
它提供了非常人性化的操作。类似 phpMyAdmin(PHP开发的MySql管理工具)。
Rockmongo 下载地址:https://github.com/iwind/rockmongo
安装
需求
一个能运行PHP的Web服务器,比如Apache Httpd, Nginx ...
PHP - 需要PHP v5.1.6或更高版本,需要支持SESSION
为了能连接MongoDB,你需要安装php_mongo扩展
使用Docker
FROM php:5.6-fpm
COPY ./ /var/www/html/
MAINTAINER Stephen "nswlp@nswlp.cn"
ENV LANG C.UTF-8
ARG timezone
RUN echo "deb http://mirrors.aliyun.com/debian stretch main contrib non-free" > /etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/debian stretch main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/debian stretch-updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/debian stretch-updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free" >> /etc/apt/sources.list
ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \
SWOOLE_VERSION=4.5.2
RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list
# Libs
RUN apt-get update && \
apt-get install -y curl \
wget \
telnet \
vim \
subversion \
nginx \
supervisor \
zlib1g-dev \
libzip-dev \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libssl-dev
# PHP Library
RUN docker-php-ext-install zip \
pdo \
pdo_mysql \
opcache \
mysqli \
bcmath \
sockets \
pcntl
# Clean apt cache
RUN rm -rf /var/lib/apt/lists/*
# composer
#RUN php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" && \
# php composer-setup.php --install-dir=/usr/local/bin --filename=composer && \
# php -r "unlink('composer-setup.php');" && \
# composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
#更新其协议,再安装。
#RUN pecl channel-update pecl.php.net
# Redis
#RUN pecl install redis && \
# rm -rf /tmp/pear && \
# docker-php-ext-enable redis
#mongodb
#RUN cp mongo-1.6.12.tgz /mongo/ && \
RUN mkdir -p mongo && \
tar -xf mongo-1.6.12.tgz -C mongo --strip-components=1 && \
cd mongo && \
phpize && \
./configure && \
make && make install && \
docker-php-ext-enable mongo
#RUN pecl install mongo && \
# rm -rf /tmp/pear && \
# docker-php-ext-enable mongo
# Swoole
#RUN wget https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz -O swoole.tar.gz && \
# mkdir -p swoole && \
# tar -xf swoole.tar.gz -C swoole --strip-components=1 && \
# rm swoole.tar.gz && \
# ( \
# cd swoole && \
# phpize && \
# ./configure --enable-mysqlnd --enable-sockets --enable-openssl --enable-http2 && \
# make -j$(nproc) && \
# make install \
# ) && \
# rm -r swoole && \
# docker-php-ext-enable swoole
# GD Library
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ && \
docker-php-ext-install -j$(nproc) gd
# Timezone
RUN cp /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && \
echo "${TIMEZONE}" > /etc/timezone && \
echo "[Date]\ndate.timezone=${TIMEZONE}" > /usr/local/etc/php/conf.d/timezone.ini
# Clean
RUN apt-get clean && rm -rf /var/cache/apt/*
COPY ./nginx.conf /etc/nginx/sites-enabled/default
COPY ./supervisord.conf /etc/supervisor/
WORKDIR /var/www/html
EXPOSE 80
CMD /usr/bin/supervisord ;chmod -R 777 /var/www/html上述配置针对采用阿里云提供的debian 7(stretch)的镜像源 更多查看查看:
在 PHP 官网上下载 MongoDB PHP 驱动包,下载地址:
https://pecl.php.net/package/mongo
下载后和dockerfile放同一目录, 这里下载的是mongo-1.6.12.tgz
nginx.conf
server
{
listen 80;
server_name _;
root /var/www/html;
index index.html index.htm index.php;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_split_path_info ^(.+?\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
}
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|tiff|ttf|svg)$ {
expires 5d;
}
location ~ /\. {
log_not_found off;
deny all;
}
location ~ /\.(?!well-known).* {
deny all;
}
}supervisord.conf
; supervisor config file
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
nodaemon=true
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[include]
files = /etc/supervisor/conf.d/*.conf
[program:php]
command=/usr/local/sbin/php-fpm --nodaemonize
[program:nginx]
command=/usr/sbin/nginx -g 'daemon off;'
[program:cron]
command=cron -f其他操作
用编辑器打开config.php,修改host, port, admins等参数
/** * Configuration of MongoDB servers * * @see more details at http://rockmongo.com/wiki/configuration?lang=en_us */ $MONGO["servers"][$i]["mongo_name"] = "mongo";//mongo server name //$MONGO["servers"][$i]["mongo_sock"] = "/var/run/mongo.sock";//mongo socket path (instead of host and port) // 这里是本例中docker的ip $MONGO["servers"][$i]["mongo_host"] = "172.17.0.13";//mongo host $MONGO["servers"][$i]["mongo_port"] = "27017";//mongo port $MONGO["servers"][$i]["mongo_timeout"] = 0;//mongo connection timeout //$MONGO["servers"][$i]["mongo_db"] = "MONGO_DATABASE";//default mongo db to connect, works only if mongo_auth=false //$MONGO["servers"][$i]["mongo_user"] = "MONGO_USERNAME";//mongo authentication user name, works only if mongo_auth=false //$MONGO["servers"][$i]["mongo_pass"] = "MONGO_PASSWORD";//mongo authentication password, works only if mongo_auth=false $MONGO["servers"][$i]["mongo_auth"] = false;//enable mongo authentication? $MONGO["servers"][$i]["control_auth"] = false;//enable control users, works only if mongo_auth=false $MONGO["servers"][$i]["control_users"]["admin"] = "admin";//one of control users ["USERNAME"]=PASSWORD, works only if mongo_auth=false $MONGO["servers"][$i]["ui_only_dbs"] = "";//databases to display $MONGO["servers"][$i]["ui_hide_dbs"] = "";//databases to hide $MONGO["servers"][$i]["ui_hide_collections"] = "";//collections to hide $MONGO["servers"][$i]["ui_hide_system_collections"] = false;//whether hide the system collections
在浏览器中访问index.php,比如说:http://localhost/rockmongo/index.php
使用用户名和密码登录,默认为"admin"和"admin"
开始玩转MongoDB!
可能出现的问题
openssl/evp.h: No such file or directory
sudo apt-get update sudo apt-get install libssl-dev



