From 50c7a0393c4e50fd3fd31dae1da3f73b7956f14a Mon Sep 17 00:00:00 2001 From: Dennis Mo Date: Sun, 26 Apr 2020 19:38:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9B=BA=E5=AE=9AIP=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E3=80=82=E5=AF=B9=E5=BA=94=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gitea/README.md | 40 +++++++++++++++---- Gitea/gitea/docker-compose.yml | 9 ++++- .../sampleApp/docker-compose.yml | 23 +++++++---- .../server/nginx/conf/conf.d/sample.conf | 9 +---- 4 files changed, 56 insertions(+), 25 deletions(-) diff --git a/Gitea/README.md b/Gitea/README.md index 5cd0278..e5b9386 100644 --- a/Gitea/README.md +++ b/Gitea/README.md @@ -28,17 +28,39 @@ https://gitea.io/en-us/ 6. 执行该sh脚本。注意,可以通过tail -2 /etc/passwd和tail -2 /etc/group 查看新注册用户的uid和gid。如和docker-compose.yml中的不符合则应修改yml文件。 -7. 参照NginxAndLetsencrypt的sample.conf中的注释说明和sampleApp中的compose文件修改docker-compose.yml的网络设置。 +7. 执行 docker inspect nginxdocker_nginx_1 来确定nginx所在网络名称: -8. 启动服务 - -9. ``` - docker-compose up -d + ``` + "Networks": { + "nginxdocker_default": { ``` -10. 参照NginxAndLetsencrypt的sample.conf中的注释说明,获取新创建的container的ip,并返回到gitea.conf中将ip填入。 +8. 执行 docker network inspect nginxdocker_default 来确定一些网络信息: + + ``` + "IPAM": { + "Driver": "default", + "Options": null, + "Config": [ + { + "Subnet": "192.168.16.0/20", + "Gateway": "192.168.16.1" + } + ] + }, + ``` + +9. 根据上述两点网络相关的信息修改gitea的docker-compose文件中的对应部分,并指定固定IP。 + +9. 将需要nginx代理的应用设置的固定IP填入之前的gitea.conf。 11. 重启nginx的docker容器。 + +12. 启动gitea的docker-compose + +13. ``` + docker-compose up -d + ``` ## 使用说明 - 配置文件在:/srv/gitea/gitea/gitea/conf下的app.ini @@ -48,4 +70,8 @@ https://gitea.io/en-us/ ## 测试环境 -* CentOS Linux release 7.3.1611 (Core) \ No newline at end of file +* CentOS Linux release 7.3.1611 (Core) + + ``` + + ``` \ No newline at end of file diff --git a/Gitea/gitea/docker-compose.yml b/Gitea/gitea/docker-compose.yml index 9fce031..c1ad877 100644 --- a/Gitea/gitea/docker-compose.yml +++ b/Gitea/gitea/docker-compose.yml @@ -5,6 +5,9 @@ networks: gitea: external: name: nginxdocker_default + ipam: + config: + - subnet: 192.168.16.0/20 services: server: @@ -19,7 +22,8 @@ services: - DB_PASSWD=Whynotfight? restart: always networks: - - gitea + gitea: + ipv4_address: 192.168.16.15 volumes: - ./gitea:/data ports: @@ -37,7 +41,8 @@ services: - MYSQL_PASSWORD=Whynotfight? - MYSQL_DATABASE=gitea networks: - - gitea + gitea: + ipv4_address: 192.168.16.14 volumes: - ./mysql/config/my.cnf:/etc/my.cnf - ./mysql/data:/var/lib/mysql diff --git a/NginxAndLetsencrypt/sampleApp/docker-compose.yml b/NginxAndLetsencrypt/sampleApp/docker-compose.yml index ea49ad3..53ada1d 100644 --- a/NginxAndLetsencrypt/sampleApp/docker-compose.yml +++ b/NginxAndLetsencrypt/sampleApp/docker-compose.yml @@ -1,10 +1,13 @@ + version: "3.4" -# setting networks. important when connecting other containers. networks: gitea: external: name: nginxdocker_default + ipam: + config: + - subnet: 192.168.16.0/20 services: server: @@ -16,10 +19,11 @@ services: - DB_HOST=db:3306 - DB_NAME=gitea - DB_USER=gitea - - DB_PASSWD=pwd + - DB_PASSWD=dbpwd restart: always networks: - - gitea + gitea: + ipv4_address: 192.168.16.15 volumes: - ./gitea:/data ports: @@ -29,14 +33,17 @@ services: - db db: - image: "mysql:5.7.27" + image: "mysql/mysql-server" restart: always environment: - - MYSQL_ROOT_PASSWORD=rootpwd + - MYSQL_ROOT_PASSWORD=dbrootpwd - MYSQL_USER=gitea - - MYSQL_PASSWORD=pwd + - MYSQL_PASSWORD=dbpwd - MYSQL_DATABASE=gitea networks: - - gitea + gitea: + ipv4_address: 192.168.16.14 volumes: - - ./mysql:/var/lib/mysql + - ./mysql/config/my.cnf:/etc/my.cnf + - ./mysql/data:/var/lib/mysql + - ./mysql/init:/docker-entrypoint-initdb.d \ No newline at end of file diff --git a/NginxAndLetsencrypt/server/nginx/conf/conf.d/sample.conf b/NginxAndLetsencrypt/server/nginx/conf/conf.d/sample.conf index 1862c69..e696795 100644 --- a/NginxAndLetsencrypt/server/nginx/conf/conf.d/sample.conf +++ b/NginxAndLetsencrypt/server/nginx/conf/conf.d/sample.conf @@ -23,14 +23,7 @@ server { ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; location / { - #˴IPDocker ContainerIPע⣺ - #1Ҫcompose nginxletsencryptĽ׶ξú - #2ɺִ docker inspect nginxdocker_nginx_1 ȷơ磺 - #"Networks": { - # "nginxdocker_default": { - #3ڽҪеӦõdocker-composeļָⲿΪơμsampleAppʾ - #4docker inspectȷӦõcontainerIP·ɡ - proxy_pass http://172.17.0.1:17000; + proxy_pass http://192.168.16.15:3000; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;