Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker build certbot e-mail input

Tags:

docker

certbot

I am trying to spin up a webapp using docker build. For generating certs, I want to use certbot. However, if I just put

RUN certbot --nginx,

I get

Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): Plugins selected: Authenticator nginx, Installer nginx
An unexpected error occurred:
EOFError.

Is there a way to provide this information in the Dockerfile or ignore it ?

like image 944
Paul Rousseau Avatar asked Jul 12 '26 05:07

Paul Rousseau


1 Answers

RUN certbot -n -m ${EMAIL} -d ${DOMAINS} --nginx

My one suggestion is not to do this during docker build, but instead generate the cert when the container starts up. This is because letsencrypt will attempt to connect to your server at the domains you're specifying, which probably is not where you're building the image.

To decrease startup time though, you'll want to skip bootstrapping dependencies (but you will need these installed). For this purpose, I would use the following command in your Dockerfile to list certificates (this will ensure dependencies are properly installed) and then alter the CMD (assuming you're using the nginx image)

Dockerfile:

ARG [email protected]
ARG DOMAINS_ARG=example.com

ENV EMAIL=${EMAIL_ARG}
ENV DOMAINS=${DOMAINS_ARG}

RUN certbot --help
...
CMD ["sh", "-c", "certbot --no-bootstrap -n -m ${EMAIL} -d ${DOMAINS} --nginx", "&&", "nginx", "-g", "daemon off;"]

The -n is for non-interactive mode
The --no-bootstrap is to skip the bootstrapping of dependencies (installing python and such)
The -m is to specify the email used for important notifications
The -d is to specify a comma separated list of domains

Using "sh", "-c" will invoke a shell when the command is executed, so you'll get the shell like behavior of replacing your environment variables with their values. Passing the values in to the build as build args doesn't expose them at startup time of your container, which is why they are then being placed into environment variables. The added benefit of them being used from environment variables is you can override these values in different environments (dev, test, stage, prod, etc...).

like image 155
Tom Delaney Avatar answered Jul 13 '26 23:07

Tom Delaney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!