The following commmand will create a cert file, cert.pem, and a key file, key.pem at the current path, where corresponded name specified in –subj can be referred to at [1].
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=${Country Name}/ST=${State or Province Name}/L=${Locality}/O=${Organization}/OU=${Organization Unit}/CN=${Common Name}"
Specify ssl port 443, certificate, and key files information.
server {
listen 80 default_server;
443 ssl;
listen [::]:443 ssl;
server_name _;
root ...;
ssl_certificate /root/ssl/cert.pem;
ssl_certificate_key /root/ssl/key.pem;
...
}
Copy the created cert and key files to docker with the setup below. Docker compose command will pick it up when during the execution.
nginx:
image: nginx:alpine
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx:/etc/nginx/conf.d:ro
- ./ssl/key.pem:/root/ssl/key.pem # copy key.pem file to /root/ssl/key.pem
- ./ssl/cert.pem:/root/ssl/cert.pem # copy cert.pem file to /root/ssl/cert.pem
- ... # other settings
networks:
- ...
depends_on:
- ...
logging: ...