Containerized NGINX needs access to certificate files and the correct TLS configuration. This guide covers mounts, configuration, and renewal.
1. Preparation
1. Obtain an SSL/TLS certificate
Before deployment, prepare:
- A certificate issued through CertOne, Let's Encrypt, or another provider
- A certificate file (.crt or .pem)
- A private key file (.key)
- An intermediate certificate chain file, when required
2. Prepare Docker
- Install Docker
- Pull an NGINX image
- Understand basic Docker operations
2. Prepare certificate files
1. Create a certificate directory
mkdir -p /path/to/ssl
2. Copy certificate files
# Copy the certificate files.
cp certificate.crt /path/to/ssl/
cp private.key /path/to/ssl/
cp chain.crt /path/to/ssl/
3. Set file permissions
chmod 644 /path/to/ssl/certificate.crt
chmod 600 /path/to/ssl/private.key
chmod 644 /path/to/ssl/chain.crt
3. NGINX configuration
1. Create the configuration
Create nginx.conf:
server {
listen 443 ssl http2;
server_name example.com;
ssl_certificate /etc/nginx/ssl/certificate.crt;
ssl_certificate_key /etc/nginx/ssl/private.key;
ssl_trusted_certificate /etc/nginx/ssl/chain.crt;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
ssl_prefer_server_ciphers off;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
server {
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
2. Create a Dockerfile (optional)
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY ssl/ /etc/nginx/ssl/
EXPOSE 80 443
4. Run the container
1. With docker run
docker run -d \
--name nginx-ssl \
-p 80:80 \
-p 443:443 \
-v /path/to/ssl:/etc/nginx/ssl:ro \
-v /path/to/nginx.conf:/etc/nginx/conf.d/default.conf:ro \
nginx:alpine
2. With Docker Compose
Create docker-compose.yml:
version: '3'
services:
nginx:
image: nginx:alpine
container_name: nginx-ssl
ports:
- "80:80"
- "443:443"
volumes:
- ./ssl:/etc/nginx/ssl:ro
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
restart: unless-stopped
Start the container:
docker-compose up -d
5. Automate deployment with CertOne
1. Create a deployment node
- Sign in to CertOne
- Open Deployment nodes
- Click Create deployment node
- Select Docker → NGINX
2. Configure deployment
- Configure the container for the selected deployment method
- Set the certificate path or mount
- Configure the service reload command
- Test the connection
3. Associate a certificate
- Select the certificate to deploy
- Select the deployment node
- Enable automatic deployment
- Renewed certificates will be deployed to the container
6. Automatic renewal
1. Renew automatically with CertOne
- Enable auto-renewal in the certificate settings
- Configure deployment to the Docker container
- Reload or restart the service after the certificate is replaced
2. Script-based renewal
Create an update script, update-cert.sh:
#!/bin/bash
# Download the replacement certificate.
# Insert your certificate download command here.
# Copy the certificate files.
cp new_certificate.crt /path/to/ssl/certificate.crt
cp new_private.key /path/to/ssl/private.key
# Restart the container.
docker restart nginx-ssl
Verify the configuration
1. Check container status
docker ps | grep nginx-ssl
2. Check HTTPS access
- Visit https://your-domain.com
- Inspect the browser's connection security indicator
- Confirm the certificate details
3. Inspect container logs
docker logs nginx-ssl
8. Common issues
1. Certificate permissions
Problem: the container cannot read the certificate files.
Resolution:
- Check file permissions
- Use a read-only
:romount where appropriate - Check ownership
2. Renewal does not take effect
Problem: the container still serves the old certificate.
Resolution:
- Reload the service or restart the container
- Confirm that the mounted certificate files were updated
- Use CertOne automatic deployment
3. Port conflicts
Problem: port 80 or 443 is already in use.
Resolution:
- Identify the process using the port
- Adjust port mappings
- Stop the conflicting service if appropriate
Best practices
1. Certificate management
- ✅ Use CertOne automatic deployment
- ✅ Back up certificate files regularly
- ✅ Monitor certificate expiration
2. Container configuration
- ✅ Use read-only mounts where appropriate
- ✅ Configure restart policies
- ✅ Add health checks
3. Security configuration
- ✅ Use secure TLS protocols
- ✅ Configure security response headers
- ✅ Limit container privileges
Conclusion
Correct certificate mounts and NGINX configuration enable HTTPS in Docker. Plan renewal and service reloads together.
Key points:
- ✅ Make certificate files available in the container
- ✅ Configure NGINX TLS
- ✅ Use CertOne automatic deployment
- ✅ Automate certificate renewal
CertOne supports deployment to Docker containers, helping automate certificate issuance and management.