文件目录结构:
[root@docker docker_dbmonitor]# ls -lrt
total 12
drwxr-xr-x. 2 root root 42 May 20 09:02 nginx
drwxr-xr-x. 3 root root 18 May 20 17:44 db_monitor_vue
-rw-r--r--. 1 root root 985 May 21 09:02 docker-compose.yml
drwxr-xr-x. 6 polkitd input 4096 May 21 09:31 mysql
drwxr-xr-x. 18 root root 4096 May 21 09:54 db_monitor
--docker-compose.yml
[root@docker docker_dbmonitor]# cat docker-compose.yml
version: '3'
services:
db:
image: mysql:5.7.22
expose:
- "3306"
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql:rw
environment:
- MYSQL_DATABASE=db_monitor
- MYSQL_ROOT_PASSWORD=mysqld
- TZ=Asia/Shanghai
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
redis:
image: redis:3.2.1
hostname: redis
ports:
- "6379:6379"
django:
hostname: django
user: root
build:
context: ./db_monitor
dockerfile: Dockerfile
volumes:
- ./db_monitor:/usr/src/app
- /tmp/logs:/tmp
command: /bin/bash -c "sh web_start.sh && sh celery_start.sh && tail -f logs/django-web.log"
ports:
- "8000:8000"
links:
- redis
- db
depends_on:
- redis
- db
nginx:
build: ./nginx
ports:
- "8001:8001"
volumes:
- ./db_monitor_vue/dist:/usr/share/nginx/dist
links:
- django
depends_on:
- django
--nginx:
[root@docker nginx]# ls -rlt
total 8
-rw-r--r--. 1 root root 265 May 20 08:59 nginx.conf
-rw-r--r--. 1 root root 100 May 20 09:02 Dockerfile
[root@docker nginx]# cat nginx.conf
server {
listen 8001;
server_name localhost;
index index.html index.htm index.php;
root /usr/share/nginx/dist;
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
}
[root@docker nginx]# cat Dockerfile
FROM nginx
EXPOSE 8001
RUN rm /etc/nginx/conf.d/default.conf
ADD nginx.conf /etc/nginx/conf.d/
--db_monitor_vue:
存放前端打包的静态文件(dist文件)
[root@docker db_monitor_vue]# ls -lrt
total 0
drwxr-xr-x. 6 root root 88 May 20 17:38 dist
配置的后端地址(baseURL)需要先修改为自己的后端地址进行打包,参考https://github.com/gumengkai/db_monitor_vue
--db_monitor:
存放后端django项目文件
Oracle instant client 因为官网下载太慢就没放到dockerfile里面,建议自行下载然后放在如下的soft文件夹中,客户端版本跟根据目标Oracle数据库的版本选择
[root@docker docker_dbmonitor]# cd db_monitor
[root@docker db_monitor]# ls -lrt
total 48
-rw-r--r--. 1 root root 3994 May 20 08:58 README.md
-rw-r--r--. 1 root root 0 May 20 08:58 __init__.py
-rw-r--r--. 1 root root 61 May 20 08:58 celery_shutdown.sh
drwxr-xr-x. 2 root root 108 May 20 08:58 images
drwxr-xr-x. 3 root root 55 May 20 08:58 install
-rw-r--r--. 1 root root 630 May 20 08:58 manage.py
-rw-r--r--. 1 root root 3541 May 20 08:58 maincheck.py
-rw-r--r--. 1 root root 924 May 20 08:58 requirements.txt
drwxr-xr-x. 5 root root 67 May 20 08:58 templates
-rw-r--r--. 1 root root 63 May 20 08:58 web_shutdown.sh
drwxr-xr-x. 4 root root 213 May 20 10:19 system
drwxr-xr-x. 4 root root 179 May 20 10:19 assets
drwxr-xr-x. 5 root root 215 May 20 10:19 oracle
drwxr-xr-x. 4 root root 179 May 20 10:19 linux
drwxr-xr-x. 4 root root 179 May 20 10:19 mysql
drwxr-xr-x. 4 root root 179 May 20 10:19 rds
drwxr-xr-x. 3 root root 252 May 20 10:19 utils
drwxr-xr-x. 3 root root 4096 May 20 10:19 check
drwxr-xr-x. 2 root root 109 May 20 10:19 logs
-rw-r--r--. 1 root root 132 May 20 14:52 web_start.sh
drwxr-xr-x. 3 root root 110 May 20 16:55 db_monitor
-rw-r--r--. 1 root root 185 May 20 18:44 celery_start.sh
drwxr-xr-x. 3 root root 72 May 21 08:49 soft
-rw-r--r--. 1 root root 318 May 21 09:24 Dockerfile
[root@docker soft]# ls -lrt
total 32
drwxr-xr-x. 3 root root 4096 May 20 15:52 instantclient_19_5
--Dockerfile
dockerfile中的环境变量根据自己的instantclient版本修改
[root@docker db_monitor]# cat Dockerfile
FROM centos/python-36-centos7
USER root
run yum -y install libaio.x86_64
RUN mkdir /usr/src/app
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN pip install -r requirements.txt --index-url https://pypi.doubanio.com/simple
ENV PYTHONOPTIMIZE=1
ENV LD_LIBRARY_PATH=/usr/src/app/soft/instantclient_19_5
EXPOSE 8000
--打包
1. docker-compose build
[root@docker docker_dbmonitor]# docker-compose build
2. docker-compose up -d
[root@docker docker