Below is a step-by-step guide to creating a Docker container that uses Certbot with the DNS plugin for certbot-dns-google to auto-renew certificates for the domains *.ef0.us and *.ef1.us. This guide assumes you have:
Docker installed on your system.
A Google Cloud Platform (GCP) account with the DNS API enabled.
Credentials set up for a service account with permissions to modify your DNS zones in GCP.
Step 1: Create a Service Account and Download JSON Key File
Navigate to the GCP Console > IAM & Admin > Service accounts.
Create a new service account or use an existing one with the necessary permissions (DNS Administrator role).
Step-by-Step for Beginners :
Go to the GCP Console .
Navigate to IAM & Admin > Service Accounts .
Click on Create Service Account and follow the prompts.
Ensure the role DNS Administrator is assigned.
Generate a new key for this service account in JSON format and download it. Name it, for example, gcp-dns-service-account.json.
Step 2: Prepare the Docker Environment
Create a directory for your project (e.g., certbot-google-dns) and navigate into it.
Create a subdirectory named certs to store your certificates.
Move the gcp-dns-service-account.json file into your project directory.
Step 3: Configure Certbot
Create a file named certbot.cfg in your project directory with the following content, adjusting the domains as specified:
ini Copy code
# certbot.cfg
# Google DNS API credentials
dns_google_credentials = /etc/letsencrypt/gcp-dns-service-account.json
dns_google_propagation_seconds = 120
# Domains to request certificates for
domains = *.ef0.us, *.ef1.us
# Email and agreement
email = your_email@example.com
agree-tos = True
# Non-interactive
non-interactive = True
# Renewal settings
renew-by-default = True
Replace your_email@example.com with your actual email address.
Adjust dns_google_propagation_seconds if needed (time to wait for DNS changes to propagate).
Step 4: Docker Compose File
Create a file named docker-compose.yml in your project directory with the following content:
yaml Copy code
version: '3'
services:
certbot:
image: certbot/dns-google
volumes:
- ./certs:/etc/letsencrypt
- ./gcp-dns-service-account.json:/etc/letsencrypt/gcp-dns-service-account.json
- ./certbot.cfg:/etc/letsencrypt/cli.ini
command: certonly --dns-google --dns-google-credentials /etc/letsencrypt/gcp-dns-service-account.json --dns-google-propagation-seconds 120 --agree-tos --email your_email@example.com --non-interactive --expand --domains -d *.ef0.us,*.ef1.us
restart: unless-stopped
cron:
image: apache/cron
volumes:
- ./certs:/etc/letsencrypt
- ./certbot.cfg:/etc/letsencrypt/cli.ini
- ./gcp-dns-service-account.json:/etc/letsencrypt/gcp-dns-service-account.json
- ./crontab:/etc/cron.d/certbot-cron
restart: unless-stopped
# Create a crontab file for automatic renewal
# (Add the following to a new file named `crontab` in the same directory)
# m h dom mon dow command
# 0 0 * * * root docker exec certbot certbot renew --quiet --non-interactive --dns-google --dns-google-credentials /etc/letsencrypt/gcp-dns-service-account.json --dns-google-propagation-seconds 120
Ensure the email in the docker-compose.yml matches the one in certbot.cfg.
The cron service is for automatic renewal. Adjust the cron job timing in the crontab file as needed (the example runs daily at midnight).
Step 5: Run Your Docker Containers
Navigate to your project directory in the terminal/command prompt.
Execute the following command to start your containers in detached mode:
bash Copy code
docker-compose up -d
Verify the initial certificate creation by checking the container logs or the certs directory:
bash Copy code
docker-compose logs -f certbot
Step 6: Automatic Renewal
The cron service in the Docker Compose setup is configured to renew certificates automatically. Ensure the cron job timing suits your needs.
Verify the cron service is running and scheduled correctly:
bash Copy code
docker-compose exec cron crontab -l
Troubleshooting Tips
Check Docker logs for any service using docker-compose logs -f <service_name>.
Verify DNS propagation if certificates are not issued as expected.
Consult Certbot logs within the certs directory for more detailed error messages.
Wildcard Certificate Issues :
Ensure your DNS setup supports wildcard records.
Validate that the _acme-challenge TXT records are correctly propagated.
Common Errors :
Propagation Timeout : Increase dns_google_propagation_seconds if timeouts occur.
Permission Errors : Verify your service account has the DNS Administrator role.
Certificate Renewal Failures : Check the cron job schedule and Certbot logs for renewal attempts.
This setup should automatically obtain and renew SSL/TLS certificates for *.ef0.us and *.ef1.us using Certbot with the Google DNS plugin via Docker.