whefter/cron 部署 - 计划任务 安装部署 Dockerfile docker rancher


https://hub.docker.com/r/whefter/cron

https://github.com/whefter/docker-cron


docker run -d  --net=host  --name cron  --restart=always  --privileged  -v "/var/run/docker.sock:/var/run/docker.sock"  -v /data/file:/data/file  -e CRON__BACKUP="0 3 * * * echo ok >> /data/file/$(date +%Y%m%d).txt"  hub.htmltoo.com:5000/http:cron


docker exec -it cron  /bin/bash


cron:

    image: whefter/cron

    restart: always

    # Recommend to minimize exposure

    network_mode: none

    volumes:

      - "/var/run/docker.sock:/var/run/docker.sock"

    environment:

      - "CRON_FOO=0 3 * * * root curl https://api.your-service.org/cron.php"

      - "CRON_BACKUP=0 4 * * * root rsync -a /opt /mnt/backup/opt"

      - "CRON_DOCKER=30 4 * * * root docker exec service-container /backup.sh"



Dockerfile:

FROM ubuntu:18.04
RUN apt-get update \
    && apt-get -y install dumb-init cron \
        apt-transport-https \
        ca-certificates \
        curl \
        gnupg2 \
        software-properties-common \
    && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
    && add-apt-repository \
        "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
       $(lsb_release -cs) \
       stable" \
    && apt-get update \
    && apt-get -y install docker-ce-cli \
    && apt-get purge -y \
        apt-transport-https \
        gnupg2 \
        software-properties-common \
    && apt-get autoremove --purge -y \
    && apt-get clean -y \
    && rm -rf /tmp/* /var/lib/apt/lists/*
ADD start.sh /start.sh
RUN chmod +x /start.sh
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["/start.sh"]

start.sh

#!/bin/bash
cronfile=/etc/crontab
cat /dev/null > "${cronfile}"
for cronvar in ${!CRON_*}; do
        cronvalue=${!cronvar}
        echo "Installing: $cronvalue"
        FIRSTPART=$(echo "$cronvalue" | cut -d " " -f 1-6)
        SECONDPART=$(echo "$cronvalue" | cut -d " " -f 7-)
        NAME="CRON: ${cronvalue}"
        echo "${FIRSTPART} echo ${NAME@Q} > /proc/1/fd/1 && ${SECONDPART} >/proc/1/fd/1 2>/proc/1/fd/2" >> "${cronfile}"
done
chmod 0644 "${cronfile}"
echo "[$(date -Iseconds)] Starting cron in foreground"
cron -f


docker pull  whefter/cron

docker tag whefter/cron hub.htmltoo.com:5000/http:cron

docker commit -m="update" -a="htmltoo.com"  cron    hub.htmltoo.com:5000/http:cron  

docker push hub.htmltoo.com:5000/http:cron


签名:这个人很懒,什么也没有留下!
最新回复 (0)
返回