I have a webapp that uses React/nginx for the frontend and Node.js for the backend. I want to create a Docker composition that not only spins up the frontend and backend but also takes cares of the TLS certificates. I ran my docker-compose.yaml one many times and now certbot says that I’ve exceeded the rate limit for requesting a certificate. However, I’m able to run certbot commands on my host machine without any issues. I don’t understand why the Docker container has this issue.
Certbot Dockerfile:
<code>FROM python:3.9 AS certbot_installer
RUN pip install certbot
FROM certbot_installer AS certbot_runner
CMD ["sh", "-c", "certbot certonly --standalone --agree-tos --email email.com -d domain.net && trap exit TERM; while :; do certbot renew; sleep 24h; done"]
</code>
<code>FROM python:3.9 AS certbot_installer
RUN pip install certbot
FROM certbot_installer AS certbot_runner
CMD ["sh", "-c", "certbot certonly --standalone --agree-tos --email email.com -d domain.net && trap exit TERM; while :; do certbot renew; sleep 24h; done"]
</code>
FROM python:3.9 AS certbot_installer
RUN pip install certbot
FROM certbot_installer AS certbot_runner
CMD ["sh", "-c", "certbot certonly --standalone --agree-tos --email email.com -d domain.net && trap exit TERM; while :; do certbot renew; sleep 24h; done"]
Node.js Dockerfile:
<code>
FROM node:alpine as build
WORKDIR /node
COPY package*.json ./
RUN npm install --silent
COPY . .
CMD npm start
React Dockerfile:
FROM node:alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
RUN mkdir -p /var/www/OnlineTutors/client/build
COPY --from=build /app/build /var/www/OnlineTutors/client/build
COPY ./nginx.conf /etc/nginx/nginx.conf
CMD nginx -g "daemon off;"
</code>
<code>
FROM node:alpine as build
WORKDIR /node
COPY package*.json ./
RUN npm install --silent
COPY . .
CMD npm start
React Dockerfile:
FROM node:alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
RUN mkdir -p /var/www/OnlineTutors/client/build
COPY --from=build /app/build /var/www/OnlineTutors/client/build
COPY ./nginx.conf /etc/nginx/nginx.conf
CMD nginx -g "daemon off;"
</code>
FROM node:alpine as build
WORKDIR /node
COPY package*.json ./
RUN npm install --silent
COPY . .
CMD npm start
React Dockerfile:
FROM node:alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
RUN mkdir -p /var/www/OnlineTutors/client/build
COPY --from=build /app/build /var/www/OnlineTutors/client/build
COPY ./nginx.conf /etc/nginx/nginx.conf
CMD nginx -g "daemon off;"
docker-compose.yaml:
<code>services:
certbot:
build:
context: ./certbot
dockerfile: Dockerfile
container_name: certbot
restart: unless-stopped
volumes:
- ./certs:/etc/letsencrypt
networks:
- app-network
frontend:
depends_on:
- certbot
build:
context: ./client
dockerfile: Dockerfile
container_name: frontend
ports:
- '80:80'
- '443:443'
volumes:
- /etc/letsencrypt:/etc/letsencrypt
networks:
- app-network
restart: unless-stopped
backend:
depends_on:
- certbot
build:
context: ./server
dockerfile: Dockerfile
container_name: backend
ports:
- '8080:8080'
volumes:
- /etc/letsencrypt:/etc/letsencrypt
networks:
- app-network
restart: unless-stopped
networks:
app-network:
driver: bridge
</code>
<code>services:
certbot:
build:
context: ./certbot
dockerfile: Dockerfile
container_name: certbot
restart: unless-stopped
volumes:
- ./certs:/etc/letsencrypt
networks:
- app-network
frontend:
depends_on:
- certbot
build:
context: ./client
dockerfile: Dockerfile
container_name: frontend
ports:
- '80:80'
- '443:443'
volumes:
- /etc/letsencrypt:/etc/letsencrypt
networks:
- app-network
restart: unless-stopped
backend:
depends_on:
- certbot
build:
context: ./server
dockerfile: Dockerfile
container_name: backend
ports:
- '8080:8080'
volumes:
- /etc/letsencrypt:/etc/letsencrypt
networks:
- app-network
restart: unless-stopped
networks:
app-network:
driver: bridge
</code>
services:
certbot:
build:
context: ./certbot
dockerfile: Dockerfile
container_name: certbot
restart: unless-stopped
volumes:
- ./certs:/etc/letsencrypt
networks:
- app-network
frontend:
depends_on:
- certbot
build:
context: ./client
dockerfile: Dockerfile
container_name: frontend
ports:
- '80:80'
- '443:443'
volumes:
- /etc/letsencrypt:/etc/letsencrypt
networks:
- app-network
restart: unless-stopped
backend:
depends_on:
- certbot
build:
context: ./server
dockerfile: Dockerfile
container_name: backend
ports:
- '8080:8080'
volumes:
- /etc/letsencrypt:/etc/letsencrypt
networks:
- app-network
restart: unless-stopped
networks:
app-network:
driver: bridge