Skip to content

Updated for Docker Compose V2 #137

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ This is useful when you need to set up nginx as a reverse proxy for an
application.

## Installation
1. [Install docker-compose](https://docs.docker.com/compose/install/#install-compose).
1. [Install docker engine](https://docs.docker.com/engine/install/).

2. Clone this repository: `git clone https://github.com/wmnnd/nginx-certbot.git .`

3. Modify configuration:
- Add domains and email addresses to init-letsencrypt.sh
- Replace all occurrences of example.org with primary domain (the first one you added to init-letsencrypt.sh) in data/nginx/app.conf
- Replace all occurrences of example.org with primary domain (the first one you will add to init-letsencrypt.sh) in data/nginx/app.conf

4. Run the init script:

./init-letsencrypt.sh

5. Run the server:
5. Answer prompt questions in terminal
- Domains, Email, Testing.

docker-compose up
6. Run the server:

docker compose up

## Got questions?
Feel free to post questions in the comment section of the [accompanying guide](https://medium.com/@pentacent/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71)
Expand Down
28 changes: 21 additions & 7 deletions init-letsencrypt.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

if ! [ -x "$(command -v docker-compose)" ]; then
echo 'Error: docker-compose is not installed.' >&2
if ! [ -x "$(command -v docker compose)" ]; then
echo 'Error: docker compose is not installed.' >&2
exit 1
fi

Expand All @@ -11,6 +11,20 @@ data_path="./data/certbot"
email="" # Adding a valid address is strongly recommended
staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits

read -p "Enter Domains (with spaces between each domain): " domains
read -p "Enter email (Adding a valid address is strongly recommended): " email
read -p "Are you testing(y/N): " -n 1 -r

if [[ $REPLY =~ ^[Yy]$ ]]
then
echo
staging=1
fi

echo "Domains: $domains"
echo "Email: $email"
echo "Testing: $staging"

if [ -d "$data_path" ]; then
read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision
if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then
Expand All @@ -30,7 +44,7 @@ fi
echo "### Creating dummy certificate for $domains ..."
path="/etc/letsencrypt/live/$domains"
mkdir -p "$data_path/conf/live/$domains"
docker-compose run --rm --entrypoint "\
docker compose run --rm --entrypoint "\
openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\
-keyout '$path/privkey.pem' \
-out '$path/fullchain.pem' \
Expand All @@ -39,11 +53,11 @@ echo


echo "### Starting nginx ..."
docker-compose up --force-recreate -d nginx
docker compose up --force-recreate -d nginx
echo

echo "### Deleting dummy certificate for $domains ..."
docker-compose run --rm --entrypoint "\
docker compose run --rm --entrypoint "\
rm -Rf /etc/letsencrypt/live/$domains && \
rm -Rf /etc/letsencrypt/archive/$domains && \
rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot
Expand All @@ -66,7 +80,7 @@ esac
# Enable staging mode if needed
if [ $staging != "0" ]; then staging_arg="--staging"; fi

docker-compose run --rm --entrypoint "\
docker compose run --rm --entrypoint "\
certbot certonly --webroot -w /var/www/certbot \
$staging_arg \
$email_arg \
Expand All @@ -77,4 +91,4 @@ docker-compose run --rm --entrypoint "\
echo

echo "### Reloading nginx ..."
docker-compose exec nginx nginx -s reload
docker compose exec nginx nginx -s reload