From e8b38500a66a3e3e8077d0add38dbe405dbfbdfe Mon Sep 17 00:00:00 2001 From: xewk Date: Sat, 6 Jan 2018 14:18:29 +0800 Subject: [PATCH 1/5] =?UTF-8?q?1.=20=E6=96=B0=E5=A2=9E=E4=BA=86=E9=98=BF?= =?UTF-8?q?=E9=87=8C=E7=9A=84=E6=BA=90=E5=9C=B0=E5=9D=80=202.=20docker=20b?= =?UTF-8?q?uild=E7=9A=84=E6=97=B6=E5=80=99=20go=20get=20-d=20./...=20?= =?UTF-8?q?=E8=BF=99=E4=B8=AA=E7=BC=96=E8=AF=91=E4=B8=8D=E8=BF=87=E5=8E=BB?= =?UTF-8?q?=20=E6=89=80=E4=BB=A5=E6=B3=A8=E9=87=8A=E6=8E=89=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1e0c6ca9..92d63653 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,19 @@ FROM golang:1.8.3-alpine3.6 +# add china aliyun repo 新增了 alpine 3.6 的阿里源 +RUN cp /etc/apk/repositories /etc/apk/repositories.back && \ + echo "https://mirrors.aliyun.com/alpine/v3.6/main/" > /etc/apk/repositories && \ + echo "https://mirrors.aliyun.com/alpine/v3.6/community/" >> /etc/apk/repositories RUN apk add --update bash git make gcc g++ ADD . /go/src/github.com/lifei6671/mindoc - WORKDIR /go/src/github.com/lifei6671/mindoc RUN chmod +x start.sh -RUN go get -d ./... && \ - go get github.com/mitchellh/gox && \ +#RUN go get -d ./... && \ # 这行 docker build 不过去,所以注释掉了 +RUN go get github.com/mitchellh/gox && \ gox -os "windows linux darwin" -arch amd64 - - CMD ["./start.sh"] From 88c9f6b18e9a54759203d25a1c8cfd68125aab2e Mon Sep 17 00:00:00 2001 From: xewk Date: Sat, 6 Jan 2018 15:18:11 +0800 Subject: [PATCH 2/5] =?UTF-8?q?1.=20=E6=96=B0=E5=A2=9E=E4=BA=86=20docker-c?= =?UTF-8?q?ompose=20=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=20docker-compose.?= =?UTF-8?q?yml=202.=E6=96=B0=E5=A2=9E=20docker-compose=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9=E5=AE=9E=E4=BE=8B=E6=96=87=E4=BB=B6env-examp?= =?UTF-8?q?le=203.=20=E6=96=B0=E5=A2=9E=E4=BA=86=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=E8=AE=BE=E7=BD=AE=EF=BC=8C=E5=B9=B6=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=BA=86=E9=A1=B9=E7=9B=AE=E5=9C=A8=E5=AE=B9=E5=99=A8=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 21 +++++++++++++++++++++ Dockerfile | 4 ++-- docker-compose.yml | 40 ++++++++++++++++++++++++++++++++++++++++ env-example | 21 +++++++++++++++++++++ start.sh | 6 +++--- 5 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 .env create mode 100644 docker-compose.yml create mode 100644 env-example diff --git a/.env b/.env new file mode 100644 index 00000000..96e01f1f --- /dev/null +++ b/.env @@ -0,0 +1,21 @@ +########################################################### +# General Setup +########################################################### + +### Application Path ################################################################################################### +# Point to your code, will be available at `/var/www/mindoc`. + +APPLICATION=../mindoc_volume/ + +### GLOBAL ENVIRONMENT ################################################################################################# + +### 数据库配置 ,如果你的数据库不在容器内或没有用 --link过 那必须要写外部数据库ip +MYSQL_PORT_3306_TCP_ADDR=192.168.4.25 +MYSQL_PORT_3306_TCP_PORT=3306 +MYSQL_INSTANCE_NAME=mindoc_db +MYSQL_USERNAME=root +MYSQL_PASSWORD=root +# expose port +HTTP_PORT=8181 + + diff --git a/Dockerfile b/Dockerfile index 92d63653..84668de8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,9 @@ RUN cp /etc/apk/repositories /etc/apk/repositories.back && \ RUN apk add --update bash git make gcc g++ -ADD . /go/src/github.com/lifei6671/mindoc +ADD . /var/www/mindoc -WORKDIR /go/src/github.com/lifei6671/mindoc +WORKDIR /var/www/mindoc RUN chmod +x start.sh diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..547e2434 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,40 @@ +version: '2' + +services: + +### Applications Code Container ############################# + + applications: + image: tianon/true + volumes: + - ${APPLICATION}:/var/www/mindoc + +### Workspace Utilities Container ########################### + + mindoc: + build: + context: ./ + env_file: .env + environment: + - MYSQL_PORT_3306_TCP_ADDR=${MYSQL_PORT_3306_TCP_ADDR} + - MYSQL_PORT_3306_TCP_PORT=${MYSQL_PORT_3306_TCP_PORT} + - MYSQL_INSTANCE_NAME=${MYSQL_INSTANCE_NAME} + - MYSQL_USERNAME=${MYSQL_USERNAME} + - MYSQL_PASSWORD=${MYSQL_PASSWORD} + - HTTP_PORT=${HTTP_PORT} + ports: + - "${HTTP_PORT}:8181" + volumes_from: + - applications + tty: true + networks: + - backend + + +### Networks Setup ############################################ + +networks: + backend: + driver: "bridge" + + diff --git a/env-example b/env-example new file mode 100644 index 00000000..96e01f1f --- /dev/null +++ b/env-example @@ -0,0 +1,21 @@ +########################################################### +# General Setup +########################################################### + +### Application Path ################################################################################################### +# Point to your code, will be available at `/var/www/mindoc`. + +APPLICATION=../mindoc_volume/ + +### GLOBAL ENVIRONMENT ################################################################################################# + +### 数据库配置 ,如果你的数据库不在容器内或没有用 --link过 那必须要写外部数据库ip +MYSQL_PORT_3306_TCP_ADDR=192.168.4.25 +MYSQL_PORT_3306_TCP_PORT=3306 +MYSQL_INSTANCE_NAME=mindoc_db +MYSQL_USERNAME=root +MYSQL_PASSWORD=root +# expose port +HTTP_PORT=8181 + + diff --git a/start.sh b/start.sh index 7ccac13f..0a5cebf2 100644 --- a/start.sh +++ b/start.sh @@ -1,7 +1,7 @@ #!/bin/sh set -e -cd /go/src/github.com/lifei6671/mindoc/ +cd /var/www/mindoc if [ ! -f "conf/app.conf" ] ; then cp conf/app.conf.example conf/app.conf @@ -45,6 +45,6 @@ fi sed -i 's/^runmode.*/runmode=prod/g' conf/app.conf -/go/src/github.com/lifei6671/mindoc/mindoc_linux_amd64 install +/var/www/mindoc/mindoc_linux_amd64 install -/go/src/github.com/lifei6671/mindoc/mindoc_linux_amd64 \ No newline at end of file +/var/www/mindoc/mindoc_linux_amd64 \ No newline at end of file From cd61774707f1e025da827be12a9172ab498f0acc Mon Sep 17 00:00:00 2001 From: xewk Date: Sat, 6 Jan 2018 15:43:39 +0800 Subject: [PATCH 3/5] =?UTF-8?q?1.=20=E5=9B=A0=E7=BC=96=E8=AF=91=E9=81=87?= =?UTF-8?q?=E5=88=B0=E9=97=AE=E9=A2=98=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=9B=9E=E6=9D=A5=E4=BA=86=EF=BC=8C=E5=90=8E?= =?UTF-8?q?=E6=9C=9F=E5=AD=A6=E4=B9=A0go=E7=9F=A5=E8=AF=86=E6=9D=A5?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=96=B0=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 ---- .gitattributes | 3 ++- Dockerfile | 4 ++-- docker-compose.yml | 3 --- start.sh | 6 +++--- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.env b/.env index 96e01f1f..ef4b28ca 100644 --- a/.env +++ b/.env @@ -2,10 +2,6 @@ # General Setup ########################################################### -### Application Path ################################################################################################### -# Point to your code, will be available at `/var/www/mindoc`. - -APPLICATION=../mindoc_volume/ ### GLOBAL ENVIRONMENT ################################################################################################# diff --git a/.gitattributes b/.gitattributes index 5f9e9e73..46f6011d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,3 @@ *.js linguist-language=Go -*.css linguist-language=Go \ No newline at end of file +*.css linguist-language=Go +./.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 84668de8..92d63653 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,9 @@ RUN cp /etc/apk/repositories /etc/apk/repositories.back && \ RUN apk add --update bash git make gcc g++ -ADD . /var/www/mindoc +ADD . /go/src/github.com/lifei6671/mindoc -WORKDIR /var/www/mindoc +WORKDIR /go/src/github.com/lifei6671/mindoc RUN chmod +x start.sh diff --git a/docker-compose.yml b/docker-compose.yml index 547e2434..8c27ac91 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,9 +6,6 @@ services: applications: image: tianon/true - volumes: - - ${APPLICATION}:/var/www/mindoc - ### Workspace Utilities Container ########################### mindoc: diff --git a/start.sh b/start.sh index 0a5cebf2..7ccac13f 100644 --- a/start.sh +++ b/start.sh @@ -1,7 +1,7 @@ #!/bin/sh set -e -cd /var/www/mindoc +cd /go/src/github.com/lifei6671/mindoc/ if [ ! -f "conf/app.conf" ] ; then cp conf/app.conf.example conf/app.conf @@ -45,6 +45,6 @@ fi sed -i 's/^runmode.*/runmode=prod/g' conf/app.conf -/var/www/mindoc/mindoc_linux_amd64 install +/go/src/github.com/lifei6671/mindoc/mindoc_linux_amd64 install -/var/www/mindoc/mindoc_linux_amd64 \ No newline at end of file +/go/src/github.com/lifei6671/mindoc/mindoc_linux_amd64 \ No newline at end of file From 9820dfa06afff3f05e0d4beea581d10594e123c0 Mon Sep 17 00:00:00 2001 From: xewk Date: Sat, 6 Jan 2018 15:44:56 +0800 Subject: [PATCH 4/5] =?UTF-8?q?1.=20=E8=BF=87=E6=BB=A4.env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index ef4b28ca..00000000 --- a/.env +++ /dev/null @@ -1,17 +0,0 @@ -########################################################### -# General Setup -########################################################### - - -### GLOBAL ENVIRONMENT ################################################################################################# - -### 数据库配置 ,如果你的数据库不在容器内或没有用 --link过 那必须要写外部数据库ip -MYSQL_PORT_3306_TCP_ADDR=192.168.4.25 -MYSQL_PORT_3306_TCP_PORT=3306 -MYSQL_INSTANCE_NAME=mindoc_db -MYSQL_USERNAME=root -MYSQL_PASSWORD=root -# expose port -HTTP_PORT=8181 - - From 859432320ef4de26af43ebb45e72c11dc248a39e Mon Sep 17 00:00:00 2001 From: xewk Date: Sat, 6 Jan 2018 15:58:43 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9F=BA=E4=BA=8Edocker-?= =?UTF-8?q?compose=E4=B8=80=E9=94=AE=E6=90=AD=E5=BB=BA=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=B8=B8=E7=94=A8=E5=91=BD=E4=BB=A4=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c6991dea..caba93a9 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,6 @@ mail_expired=30 # 使用Docker部署 - 如果是Docker用户,可参考项目内置的Dockerfile文件编译镜像。 在启动镜像时需要提供如下的环境变量: @@ -127,6 +126,28 @@ HTTP_PORT 程序监听的端口号 ```bash docker run -p 8181:8181 -e MYSQL_PORT_3306_TCP_ADDR=127.0.0.1 -e MYSQL_PORT_3306_TCP_PORT=3306 -e MYSQL_INSTANCE_NAME=mindoc_db -e MYSQL_USERNAME=root -e MYSQL_PASSWORD=123456 -e httpport=8181 -d daocloud.io/lifei6671/mindoc:latest ``` +### docker-compose 一键安装 +1. 生成配置文件 + > cp env-example .env + + 按照自己的环境填写配置信息到.env文件中 +2. 一键完成所有环境搭建 + > docker-compose up -d mindoc +3. 浏览器访问 + > http://localhost:8181/ + + 整个部署完成了 +4. 常用命令参考 + - 启动 + > docker-compose up -d mindoc + - 停止 + > docker-compose stop mindoc + - 重启 + > docker-compose restart mindoc + - 停止删除容器,释放所有资源 + > docker-compose down + + 更多 docker-compose 的使用相关的内容 请查看官网文档或百度 # 项目截图