如何保留 certbot 容器 运行?

How to keep the certbot container running?

我正在使用 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;'"

但是它忽略了睡眠命令并且容器消失了。

而 运行 以下内容:

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

保持容器向上并运行。

我想在 certbot 失败后保持容器和 运行。

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

使用 docker-compose volumes 安装它

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