如何保持certbot容器运行?

时间:2019-09-12 12:09:53

标签: docker-compose certbot

我正在使用certbot/certbot容器,如:

docker-compose run -d --rm --entrypoint 'certbot certonly --webroot -w /var/www/certbot --staging --email example@domain.se -d example.com --rsa-key-size 4096 --agree-tos --force-renewal ; sleep 3600' certbot

在以下撰写文件上:

version: '3.5'
services:
  nginx:
    image: nginx:1.15-alpine
    restart: unless-stopped
    volumes:
      - "~/dev/docker/projects/common/volumes/letsencrypt/nginx:/etc/nginx/conf.d"
      - "~/dev/docker/projects/common/volumes/letsencrypt/certbot/conf:/etc/letsencrypt"
      - "~/dev/docker/projects/common/volumes/letsencrypt/certbot/www:/var/www/certbot"
      - "~/dev/docker/projects/common/volumes/letsencrypt/nginx:/var/www/nginx"
      - "~/dev/docker/projects/common/volumes/logs:/var/log/nginx"
    ports:
      - "80:80"
      - "443:443"
    command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
  certbot:
    image: certbot/certbot
    restart: unless-stopped
    volumes:
      - "~/dev/docker/projects/common/volumes/letsencrypt/certbot/conf:/etc/letsencrypt"
      - "~/dev/docker/projects/common/volumes/letsencrypt/certbot/www:/var/www/certbot"
      - "~/dev/docker/projects/common/volumes/logs:/var/log/letsencrypt"
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"

但是它忽略了sleep命令,容器消失了。

运行以下内容:

docker-compose run -d --rm --entrypoint 'sleep 3600' certbot

保持容器正常运行。

certbot失败之后,我想保持容器的正常运行。

1 个答案:

答案 0 :(得分:0)

您可以将"/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"移到专用脚本中,例如start.sh。

通过docker-compose卷安装它

 volumes:
   - "./start.sh:/start.sh
 entrypoint: /start.sh