django-postsql数据库¶ 修正数据库配置 settings.py 1 2 3 4 5 6 7 8 9 10DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'tpcbb', 'USER': 'postgres', 'PASSWORD': 'mysecretpassword789456', 'HOST': 'db', 'PORT': '5432', } } docker-compose.yml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32version: '3' services: tp_cbbs: build: context: ./ dockerfile: ./Dockerfile restart: always ports: - 127.0.0.1:36610:8081 - 6690:9001 - 6691:5555 volumes: - ./:/home networks: - cbb_tp depends_on: - db db: image: postgres restart: always shm_size: 128mb environment: POSTGRES_PASSWORD: mysecretpassword789456 POSTGRES_USER: postgres POSTGRES_DB: tpcbb PGDATA: /var/lib/postgresql/data/pgdata volumes: - /root/auto/cbb_postsql:/var/lib/postgresql/data/pgdata networks: - cbb_tp networks: cbb_tp: 此处需要注意 : psycopg2-binary 安装依赖包使用这个¶ Dockerfile 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25FROM python:slim # 运行于 arm32位平台上的镜像 LABEL version="1.0" description="这是一个服务器;默认通过supervisord调度" by="mibo" ADD sources.list /etc/apt/ RUN apt update RUN apt install -y locales subversion procps net-tools nginx redis ENV DEBIAN_FRONTEND=noninteractive RUN pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple && \ pip3 config set install.trusted-host mirrors.aliyun.com && \ /usr/local/bin/python -m pip install --upgrade pip # django RUN pip3 install django django-grappelli uvicorn psycopg2-binary # celery RUN apt install iputils-ping expect ssh rsync -y RUN pip3 install supervisor pyecharts requests paramiko flower webssh django-celery-beat Celery "celery[redis,auth,msgpack]" xmltodict WORKDIR /home CMD bash run.sh supervisord.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68[unix_http_server] file=/tmp/supervisor.sock ; the path to the socket file ;chmod=0700 ; socket file mode (default 0700) ;chown=nobody:nogroup ; socket file uid:gid owner ;username=user ; default is no username (open server) ;password=123 ; default is no password (open server) [inet_http_server] ; inet (TCP) server disabled by default port=0.0.0.0:9001 ; ip_address:port specifier, *:port for all iface username=mibo ; default is no username (open server) password=ggicp-i%^&密码我知道了,哈哈哈,信息 ; default is no password (open server) [supervisord] logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB logfile_backups=10 ; # of main logfile backups; 0 means none, default 10 loglevel=info ; log level; default info; others: debug,warn,trace pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid nodaemon=false ; start in foreground if true; default false silent=false ; no logs to stdout if true; default false minfds=1024 ; min. avail startup file descriptors; default 1024 minprocs=200 ; min. avail process descriptors;default 200 [program:django] command=uvicorn cbb_manage.asgi:application --host 0.0.0.0 --port 8000 --ws-max-size 90000000000 --reload directory=/home # 命令执行的目录或者说执行 command 之前,先切换到工作目录 可以理解为在执行命令前会切换到这个目录 在我这基本没啥用 autostart=true #是否自动启动 autorestart=true #程序意外退出是否自动重启 redirect_stderr=true # 如果为true,则stderr的日志会被写入stdout日志文件中 理解为重定向输出的日志 [program:redis-server] command=redis-server directory=/home # 命令执行的目录或者说执行 command 之前,先切换到工作目录 可以理解为在执行命令前会切换到这个目录 在我这基本没啥用 autostart=true #是否自动启动 autorestart=true #程序意外退出是否自动重启 redirect_stderr=true # 如果为true,则stderr的日志会被写入stdout日志文件中 理解为重定向输出的日志 [program:flower] command=celery -A cbb flower --broker=redis://@loaclhost:6379/0 directory=/home # 命令执行的目录或者说执行 command 之前,先切换到工作目录 可以理解为在执行命令前会切换到这个目录 在我这基本没啥用 autostart=true #是否自动启动 autorestart=true #程序意外退出是否自动重启 redirect_stderr=true # 如果为true,则stderr的日志会被写入stdout日志文件中 理解为重定向输出的日志 [program:worker] command=celery --app cbb worker --loglevel=info directory=/home # 命令执行的目录或者说执行 command 之前,先切换到工作目录 可以理解为在执行命令前会切换到这个目录 在我这基本没啥用 autostart=true #是否自动启动 autorestart=true #程序意外退出是否自动重启 redirect_stderr=true # 如果为true,则stderr的日志会被写入stdout日志文件中 理解为重定向输出的日志 [program:beat] command=celery -A cbb beat --scheduler django_celery_beat.schedulers:DatabaseScheduler directory=/home # 命令执行的目录或者说执行 command 之前,先切换到工作目录 可以理解为在执行命令前会切换到这个目录 在我这基本没啥用 autostart=true #是否自动启动 autorestart=true #程序意外退出是否自动重启 redirect_stderr=true # 如果为true,则stderr的日志会被写入stdout日志文件中 理解为重定向输出的日志 [program:nginx] command=nginx -g 'daemon off;' directory=/etc/nginx # 命令执行的目录或者说执行 command 之前,先切换到工作目录 可以理解为在执行命令前会切换到这个目录 在我这基本没啥用 autostart=true #是否自动启动 autorestart=true #程序意外退出是否自动重启 redirect_stderr=true # 如果为true,则stderr的日志会被写入stdout日志文件中 理解为重定向输出的日志 #stdout_logfile=/home/nginx.log # 子进程的stdout的日志路径 输出日志文件 #stderr_logfile=/home/nginx.err.log # 错误日志文件 当redirect_stderr=true。这个就不用