git clone https://github.com/aileen5150/crontab-ui.git ,下载crontab-ui相关文件
pg_bak.sh内容如下:
#!/bin/bash
if [ ! -d /db ];then
mkdir /db
fi
cur_time=$(date '+%Y-%m-%d')
fifteendays_time=$(date -d-15days '+%Y-%m-%d')
rm -rf /db/$fifteendays_time.dump
echo "starting backup postgresql..."
pg_dump "host=$PG_HOST hostaddr=$PG_HOST port=$PG_PORT user=$PG_USER password=$PG_PASSWORD dbname=$PG_DATABASE" >/db/$cur_time.dump
echo "finish backup..."
Dockerfile文件中增加如下:
RUN apk --no-cache add postgresql-client
RUN apk --no-cache add bash
RUN apk --no-cache add coreutils
RUN apk --no-cache add -U tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && apk del tzdata
COPY supervisord.conf /etc/supervisord.conf
COPY . /crontab-ui
COPY pg_bak.sh /shs/pg_bak.sh
ENV PG_HOST 127.0.0.1
ENV PG_PORT 5432
ENV PG_USER postgres
ENV PG_PASSWORD 123456
ENV PG_DATABASE postgres
docker build --no-cache -t reg.ji.com/crontab-ui:0.1.2 -f ./Dockerfile . 生成image文件
docker-compose文件如下:
version: "3"
services:
portainer:
image: reg.ji.com/crontab-ui:0.1.2
restart: always
environment:
- PG_HOST=192.168.11.12
- PG_PORT=5432
- PG_USER=postgres
- PG_PASSWORD=123456
- PG_DATABASE=1912
ports:
- 8000:8000
volumes:
- "$VOLUME_PATH/crontabs:/crontab-ui/crontabs"
- "$VOLUME_PATH/db:/db"