nginx-unit docker 运行以及php &&golang 简单使用
https://github.com/rongfengliang/nginx-unit-docker-demo
a. 项目结构
├── Dockerfile // docker 构建
├── Jenkinsfile // jenkins 构建
├── README.md
├── app.go // golang 语言支持
├── docker-compose.yml // docker-compose 构建
├── run.sh // 应用配置,通过rest 接口
├── start.json // 应用配置 php && golang
└── website
└── index.php // php 语言
b. 代码说明(使用docker多阶段构建)
Dockerfile docker 构建
FROM golang:stretch AS build-env
RUN apt-get update
# RUN apt-get install -y build-essential
RUN git clone https://github.com/nginx/unit.git /go/src/github.com/nginx/unit
## 注意分之的版本 必须和你的unit 一致,不然报错,这个觉得不好,可能和目前生产可用性有关系吧
## 这个主要是golang sdk 的构建
RUN cd /go/src/github.com/nginx/unit && git checkout tags/1.1 && ./configure && ./configure go && make go-install
ADD . /go/src/github.com/rongfengliang/nginx-unit-go
RUN cd /go/src/github.com/rongfengliang/nginx-unit-go && go build -o /appdemo app.go
FROM nginx/unit:1.1-full
WORKDIR /appdemo
ADD start.json /appdemo/start.json
COPY website /appdemo/website/
COPY --from=build-env /appdemo /appdemo/website/appdemo
EXPOSE 8080 8000 8081
CMD ["/usr/sbin/unitd", "--no-daemon","--control", "0.0.0.0:8000"]
Jenkinsfile jenkinspipeline 构建
pipeline {
agent {
node {
label 'docker-65'
}
}
stages {
stage('docker-compose build') {
steps {
sh 'docker-compose build'
}
}
stage('docker-compose run ') {
steps {
sh 'docker-compose up -d'
}
}
stage('deploy service') {
steps {
sh './run.sh'
}
}
}
}
app.go golang 支持
package main
import (
"math"
"net/http"
"nginx/unit" ## 注意unit 版本,感觉做的有点不好,因为版本因为无法发布服务
)
func term(ch chan float64, k float64) {
ch <- 4 * math.Pow(-1, k) / (2*k + 1)
}
func handler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("appdemorong"))
}
func main() {
http.HandleFunc("/", handler)
//http.ListenAndServe(":8080", nil)
unit.ListenAndServe(":8089", nil)
}
docker-compose.yml 比较简单,不用说了
version: "3"
services:
nginx-unit:
build:
context: .
image: myunit
ports:
- "9080:8080"
- "9000:8000"
- "9001:8081"
run.sh 服务注册的shell
#!/bin/sh
curl -X PUT -d @$PWD/start.json http://localhost:9000
start.json 服务配置的说明
{
"listeners":{
"*:8080":{
"application":"phpindex"
},
"*:8081":{
"application":"golang"
}
},
"applications":{
"phpindex":{
"type":"php",
"processes":30,
"root":"/appdemo/website",
"index":"index.php"
},
"golang":{
"type":"go",
"processes":30,
"working_directory": "/appdemo/website",
"executable": "appdemo"
}
}
}
website/index.php php 语言支持
<?php
phpinfo()
?>
docker-compose build
docker-compose up -d
./run.sh



多版本切换以及多版本也比较简单,就是服务注册配置文件的处理,总的来说,挺好的功能,但是在微服务,以及service mesh 的大趋势之下,就显得没有那么好的,
也只是个人的观点
http://unit.nginx.org/
https://github.com/rongfengliang/nginx-unit-docker-demo
nginx-unit docker 运行以及php &&golang 简单使用的更多相关文章
- docker 运行nginx并进入容器内部、端口映射
一.docker运行容器 1.从网易蜂巢镜像仓库下载nginx镜像 : 2.拉取镜像到本地,并查看本地的镜像: $ docker pull hub.c..com/library/node:latest ...
- docker运行nginx为什么要使用 daemon off
再返回Nginx的docker仓库仔细查看说明,其实是有说明的 /捂脸- 就是在CMD后面加上exec nginx -g 'daemon off;',如下: command: /bin/bash -c ...
- docker 运行容器,安装Nginx
########################################## #运行容器 #安装Nginx #搜索.下载镜像 docker search nginx docker pull n ...
- docker 运行jenkins及vue项目与springboot项目(四.docker运行nginx)
docker 运行jenkins及vue项目与springboot项目: 一.安装docker 二.docker运行jenkins为自动打包运行做准备 三.jenkins的使用及自动打包vue项目 四 ...
- Docker 拉取Nginx镜像 和运行
Docker 镜像拉取 docker pull [OPTIONS] NAME[:TAG|@DIGEST] 镜像拉取命令 OPTIONS说明: -a :拉取所有 tagged 镜像 --disable- ...
- nginx Unit 服务器
转自: https://github.com/nginx/unit/pull/18/ 感谢: https://www.v2ex.com/t/389528 English 简体中文 繁體中文 NGINX ...
- 在 Azure 上使用 Docker运行 Mono
Docker 是最近相当热门的一个名词,它是一个基于 Linux Container 的轻量化的虚拟技术,而微软也相当积极与 Docker 合作,在 Azure 上支持这个火热的技术,并且提供简单的方 ...
- Centos7的安装、Docker1.12.3的安装,以及Docker Swarm集群的简单实例
目录 [TOC] 1.环境准备 本文中的案例会有四台机器,他们的Host和IP地址如下 c1 -> 10.0.0.31 c2 -> 10.0.0.32 c3 -> 10.0.0. ...
- Docker初步认识安装和简单实例
前话 问题 开发网站需要搭建服务器环境,FQ官网下载软件包,搭建配置nginx,apache,数据库等.官网没有直接可用的运行版本,担心网络流传的非官方发布软件包不安全还得自行编译官方源码安装,忘记步 ...
随机推荐
- Android 版本升级涉及到的数据库数据迁移问题
最近做老版本向新版本升级,新版本增加了几张表,有的表经过了增加字段.那么如何把老的数据迁移到新的版本里呢? 我写了一段伪代码,是关于我们项目里的 用户登录信息 Users表, 历史表histor ...
- gitflow工作流程基本命令使用
1 基础命令: 初始化: git flow init 开始新Feature: git flow feature start MYFEATURE Publish一个Feature(也就是push到远程) ...
- [nodejs]解决mysql和连接池(pool)自动断开问题
最近在做一个个人项目,数据库尝试使用了mongodb.sqlite和mysql.分享一下关于mysql的连接池用法.项目部署于appfog,项目中我使用连接池链接数据库,本地测试一切正常.上线以后,经 ...
- NC 工具的使用教程
NC工具的使用说明...nc使用说明 参数介绍: nc.exe -h即可看到各参数的使用方法. 基本格式:nc [-options] hostname port[s] [ports] ... nc - ...
- Linux 磁盘管理,Linux vi/vim
一.Linux 磁盘管理 Linux磁盘管理好坏直接关系到整个系统的性能问题. Linux磁盘管理常用三个命令为df.du和fdisk. df:列出文件系统的整体磁盘使用量 du:检查磁盘空间使用量 ...
- 我要复习python啦(一)
一.变量 那些曾经怎么也看不懂的东西,突然有一天就懂了.这就是复习的力量吗? 1 变量的赋值 a = 10 做了上面的图所描述的事情 1)开辟一块内存,创建一个值为10的整数 2)创建一个a的标记 3 ...
- IceScrum敏捷开发工具的安装文档-官方最新版
Welcome to the iceScrum iceScrum install guide. If you don’t want to manage your own iceScrum instal ...
- CF911A
题解: 先按照a大小排序(要双关键字) 然后和a[1]一样的按照b减一减,取最小 代码: #include<bits/stdc++.h> using namespace std; ; in ...
- 【html】META http-equiv 大全
meta是html语言head区的一个辅助性标签.几乎所有的网页里,我们可以看到类似下面这段的html代码: <head><meta http-equiv="content ...
- C++/C extern关键字详解 EntryPointNotFoundException处理
最近在弄C#帮公司做一个图像识别的功能,用到了第三方的dll,在调用dll过程中就出现了一个问题.EntryPointNotFoundException异常.遇到这种异常,很大可能就是在生成dll时函 ...