hc - docker
我们申请了1台虚拟机, 部署了docker
PROD [root@whdcbosd001 ~]# docker version
Client: Docker Engine - Community
Version: 20.10.7
API version: 1.40
Go version: go1.13.15
Git commit: f0df350
Built: Wed Jun 2 11:58:10 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 19.03.5
API version: 1.40 (minimum version 1.12)
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:24:18 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.6
GitCommit: d71fcd7d8303cbf684402823e425e9dd2e99285d
runc:
Version: 1.0.0-rc95
GitCommit: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
docker-init:
Version: 0.18.0
GitCommit: fec3683
PROD [root@whdcbosd001 ~]#
上面跑了一些容器, 有:
- gitlab-runner用于CICD
- portainer是docker容器的网页管理平台
- 4个mysql数据库
- 其他是我们组开发的应用程序
PROD [root@whdcbosd001 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b0881b404b2e portainer/portainer "/portainer" 6 weeks ago Up 6 weeks 0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp sd_portainer
11f72eef486a caller_api_oncallsolution "/bin/sh -c '\"python…" 7 weeks ago Up 7 weeks 0.0.0.0:8008->8008/tcp theapi_oncallSolution
388eecf74b28 thescanner_oncallsolution "/bin/sh -c '\"python…" 7 weeks ago Up 6 hours scanner_oncallsolution
a25cdf472188 ticketcol_oncallsolution "/bin/sh -c '\"python…" 7 weeks ago Up 7 weeks ticketcol_oncallsolution
62d6c5ba683f hcguard:v3.3 "python /opt/service…" 8 weeks ago Up 2 hours 0.0.0.0:9899->9899/tcp hcguard
7b2397bc550d sdoncallfinder:1.0 "/bin/sh -c '\"python…" 2 months ago Up 4 days 0.0.0.0:8007->8007/tcp, 9899/tcp sdoncallfinder
3a1ab6127da3 mywebapp:v0.13 "/bin/sh -c '\"python…" 3 months ago Up 8 weeks 0.0.0.0:8080->8080/tcp mywebapp
18ae27468ec3 resetidm:latest "/bin/sh -c '\"python…" 7 months ago Up 8 weeks 0.0.0.0:9999->9999/tcp resetidm
6507b661c9f1 rostercollection:2.4 "/bin/sh -c '\"python…" 7 months ago Up 8 weeks 0.0.0.0:80->80/tcp rostercollection
72dafc1e8c24 mysql:latest "docker-entrypoint.s…" 8 months ago Up 8 weeks 33060/tcp, 0.0.0.0:33062->3306/tcp cinthiemysql
24f1863bd9a7 mysql:latest "docker-entrypoint.s…" 8 months ago Up 8 weeks 33060/tcp, 0.0.0.0:33061->3306/tcp kingsleydb
c7017190dea0 mysql:latest "docker-entrypoint.s…" 9 months ago Up 8 weeks 33060/tcp, 0.0.0.0:33060->3306/tcp oncalldb
bbdd0c2debbb mysql:latest "docker-entrypoint.s…" 9 months ago Up 8 weeks 33060/tcp, 0.0.0.0:21211->3306/tcp hcguarddb2
da4bc9c4144a gitlab/gitlab-runner:latest "/usr/bin/dumb-init …" 9 months ago Up 8 weeks gitlab-runner
所用镜像
PROD [root@whdcbosd001 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
albert/albert_grafana_check_alerts latest 8f2a6e35c1a4 3 weeks ago 250MB
albert/albert_grafana_reports latest c50680218a4c 6 weeks ago 250MB
caller_api_oncallsolution latest 5fd612c7bb54 7 weeks ago 583MB
thescanner_oncallsolution latest 5a4844ef1cff 7 weeks ago 466MB
ticketcol_oncallsolution latest ae10eb10213b 7 weeks ago 309MB
hcguard v3.3 e2675dbaca2f 8 weeks ago 477MB
albert/albert_api latest 5ebdd1986867 2 months ago 132MB
sdoncallfinder 1.0 2efa64c0cd5c 2 months ago 601MB
mywebapp v0.13 292fe7fa9651 3 months ago 196MB
resolveissue v1.0 4692b017d106 6 months ago 477MB
resetidm latest d6d40a3db452 7 months ago 124MB
rostercollection 2.4 945779ef42c8 7 months ago 359MB
dtgmtkt latest e14541d5e333 8 months ago 162MB
bitnami/postgresql latest ac3883f7f7fc 10 months ago 262MB
nginx latest 605c77e624dd 10 months ago 141MB
grafana/grafana latest 9b957e098315 11 months ago 275MB
python310 instantclient12 f632c73a521a 11 months ago 466MB
docker latest 0c655f708b2a 12 months ago 216MB
python 3.10-alpine-servicedesk-base ae8d2427316b 12 months ago 427MB
python 3.10-alpine 3a16a76a1963 12 months ago 45.4MB
hcguard_base_slim latest 5be887aed46b 14 months ago 462MB
python 3.7-slim 959d1a6868be 14 months ago 120MB
mysql latest 5a4e492065c7 15 months ago 514MB
registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper x86_64-8925d9a0 92f0a7d624c2 15 months ago 72MB
gitlab/gitlab-runner latest 7f83dee88242 16 months ago 1.9GB
portainer/portainer latest 580c0e4e98b0 20 months ago 79.1MB
docker 19.03.11-dind ded0f436a6a3 2 years ago 226MB
docker 18.09.7-dind 25a1e57c7741 3 years ago 184MB
PROD [root@whdcbosd001 ~]#
Dockerfile示例
# 基础镜像
FROM python:3.7-slim
# 设置容器和宿主机时间同步
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone
# 拷贝文件
# 将此Dockerfile同级目录中的grafana_check_alerts文件夹拷贝到容器中, 放到根目录下
COPY grafana_check_alerts /grafana_check_alerts
# 将此Dockerfile同级目录中的requirements.txt拷贝到容器中, 放到/grafana_check_alerts目录下
COPY requirements.txt /grafana_check_alerts/requirements.txt
# 设置workdir
# 进入容器自动进入/grafana_check_alerts目录下
# python launcher.py的时候, 自动执行的是python /grafana_check_alerts/launcher.py
WORKDIR /grafana_check_alerts
# 设置Sources Root - -> from导入模块
ENV PYTHONPATH /grafana_check_alerts
# 安装requirements - 镜像源使用aliyun
Run pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com/
# 暴露19892端口(flask_api)
EXPOSE 19892
# 开机自启动
# ENTRYPOINT ["python", "flask_api.py"]
计划任务示例
PROD [root@whdcbosd001 ~]# crontab -l
# albert_grafana_check_alerts
# 00 10 * * * docker exec albert_grafana_check_alerts python launcher.py
PROD [root@whdcbosd001 ~]#
portainer展示


浙公网安备 33010602011771号