A comprehensive guide to implementing SSL/TLS certificates on Docker containers and services.
Before implementing SSL certificates on Docker, ensure you have:
You can obtain SSL certificates through various methods:
Create a secure way to store and access certificates:
docker volume create certs
docker run --rm -v certs:/certs -v $(pwd):/source alpine sh -c "cp /source/*.{crt,key} /certs/"
Use our configuration generator to create your Docker SSL configuration:
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY default.conf /etc/nginx/conf.d/default.conf
VOLUME /etc/nginx/certs
EXPOSE 443
CMD ["nginx", "-g", "daemon off;"]
server {
listen 443 ssl http2;
server_name example.com;
ssl_certificate /etc/nginx/certs/example.com.crt;
ssl_certificate_key /etc/nginx/certs/example.com.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://app:3000;
}
}
Verify your SSL configuration:
docker run -d --name myapp -p 443:443 -v certs:/etc/nginx/certs myapp
curl -k https://localhost
Use Docker Compose for easier SSL configuration:
version: '3.8'
services:
web:
image: nginx:alpine
ports:
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- certs:/etc/nginx/certs:ro
depends_on:
- app
app:
build: .
expose:
- "3000"
volumes:
certs:
external: true
Certellix is an independent service. We are not affiliated with any commercial certificate authority.