在服务器上利用docker-compose实现项目的容器化部署(示例)
将Gitea,Drone,Grafana,postgresql部署到服务器上面
前提是了解一些docker和docker-compose的基本命令!!!
1.Gitea
docker-compose.yml
version: '3'
services:
gitea:
image: gitea/gitea:latest
environment:
- USER=git
- GITEA__database__DB_TYPE=sqlite3
- GITEA__database__HOST=localhost:3306
- GITEA__database__NAME=gitea
- GITEA__database__USER=gitea
- GITEA__database__PASSWD=gitea
- GITEA__server__DOMAIN=服务器IP
- GITEA__server__ROOT_URL=http://<服务器IP>:3000
- GITEA__server__HTTP_PORT=3000
- GITEA__server__SSH_PORT=2222
- GITEA__server__DISABLE_SSH=false
ports:
- "3000:3000"
- "2222:22"
volumes:
- gitea_data:/data
restart: always
volumes:
gitea_data:
可以通过 http://<服务器IP>:3000/ 访问Gitea
2.grafana
docker-compose.yml
version: '3'
services:
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- 3002:3000
volumes:
- ~/grafana/data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
restart: always
部署完后通过:http://<服务器IP>:3002/ 访问
3.postgresql(数据库)
docker-compose.yml
version: '3.7'
services:
postgres:
image: postgres:latest
container_name: postgres
restart: unless-stopped
ports:
- "5432:5432"
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
POSTGRES_DB: database_blog
volumes:
- ~/postgresql/data:/var/lib/postgresql/data
4.Drone
docker-compose.yml
version: '3'
services:
drone-server:
image: drone/drone:2
container_name: drone-server
ports:
- 8000:80
volumes:
- ./drone:/data
environment:
- DRONE_GITEA_SERVER=http://<服务器IP>:3000
- DRONE_GITEA_CLIENT_ID=effc6123-d84a-4b29-bb33-5651bd928d53 # Gitea OAuth2 client ID
- DRONE_GITEA_CLIENT_SECRET=gto_bteocrxcbl6m7btzot5sh3gboabmg7ql3nuih6iwfng2jj6p4rea # Gitea OAuth2 client secret
- DRONE_RPC_SECRET=8cad9187c3548de8c489383403388cf4
- DRONE_SERVER_HOST=http://<服务器IP>:8000
- DRONE_SERVER_PROTO=http
depends_on:
- drone-runner
drone-runner:
image: drone/drone-runner-docker:1
container_name: drone-runner
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- DRONE_RPC_HOST=drone-server
- DRONE_RPC_PROTO=http
- DRONE_RPC_SECRET=8cad9187c3548de8c489383403388cf4
- DRONE_RUNNER_CAPACITY=2
- DRONE_RUNNER_NAME=runner
部署完后通过:http://<服务器IP>:8000/ 访问