Certbot doesn't know how to automatically configure the web server on this system

Garam·2024년 11월 26일
post-thumbnail

문제 상황

  • docker-compose.yml
version: '3'

services:
  nginx:
    image: nginx:1.15-alpine
    restart: unless-stopped
    volumes:
      - ./data/nginx:/etc/nginx/conf.d
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    ports:
      - "80:80"
      - "443:443"
  certbot:
    image: certbot/certbot
    restart: unless-stopped
    volumes:
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
  • certbot 컨테이너가 restart하며 해당 로그를 남기는 상황
>> docker logs ${certbot_container_id}

"
Certbot doesn't know how to automatically configure the web server on this system. 
However, it can still get a certificate for you. Please run 'certbot certonly' to do so. 
You'll need to manually configure your web server to use the resulting certificate.
"

해결

  • docker-compose.yml에 entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot certonly; sleep 12h & wait $${!}; done;'" 추가
certbot:
    image: certbot/certbot
    restart: unless-stopped
    volumes:
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot certonly; sleep 12h & wait $${!}; done;'"

원인

Certbot 컨테이너가 entrypoint를 추가하지 않으면 정상 작동하지 않는 이유는 Certbot 컨테이너 기본 설정이 인증서 발급 이후 컨테이너를 종료하도록 되어 있기 때문이다. 이 문제를 해결하기 위해 entrypoint를 수정하여 컨테이너가 인증서 발급 후에도 지속적으로 실행되도록 만들어야 한다.


Certbot 기본 동작

Certbot 기본적으로 인증서를 발급하거나 갱신한 뒤 작업이 끝나면 컨테이너가 종료된다. 이는 Certbot이 "단발성 작업"에 최적화된 도구로 설계되었기 때문이다. 그러나 Docker Compose를 사용해 Certbot을 지속 실행하도록 설정하려면 다음과 같은 이유로 기본 동작을 변경해야 한다.

  1. Docker Compose의 restart: unless-stopped 설정

    Certbot 컨테이너는 인증서를 발급 후 종료되므로 Docker는 이를 "비정상 종료"로 간주하고 컨테이너를 재시작하려고 한다.

    이 과정에서 무한 루프가 발생하며, Certbot은 매번 인증서를 발급하려고 시도하다가 실패 로그를 남긴다.

  2. 지속적인 인증서 갱신 필요

    Let's Encrypt 인증서는 90일간 유효하며, 자동 갱신을 위해 주기적으로 Certbot을 실행해야 한다. 기본 설정으로는 주기적인 갱신이 불가능하다.

0개의 댓글