Score:1

How to add self-signed certificate to docker nginx:alpine

pr flag

This is my-compose.yml definition

nginx:
  image: "nginx:alpine"
  ports:
    - 5000:80
  links:
    - registry:registry
  volumes:
    - ./auth:/etc/nginx/conf.d
    - ./auth/nginx.conf:/etc/nginx/nginx.conf:ro

registry:
  image: registry:latest
  volumes:
    - ./registry-data:/var/lib/registry

I start docker as daemon on fly

sudo docker-compose -f my-compose.yml up -d

maybe I need to add my self-signed certificate to "nginx:alpine" docker, but how exactly?

Score:1
in flag

Depending on what sort of hoops your Docker containers need to jump through, you can accomplish this with a COPY command in your DockerFile:

COPY /path/to/certificate.pem /etc/ssl/certs/nginx-selfsigned.crt;
COPY /path/to/certificate-key.key /etc/ssl/private/nginx-selfsigned.key;

Some notes:

  • if your certificates are in .pem format, do not use any transformation processes; simply rename .pem to .crt
  • copy the renamed certificates to the proper certificate location for your nginx installation
  • ensure nginx knows where the files are expected to be:
    ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
    ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
    

This should do what you need it to do

Alex avatar
pr flag
Thank you @matigo, I copy certificates inside container and check - is it present? sudo docker exec -it 705c3bb67bce cat /etc/ssl/certs/nginx-selfsigned.crt and sudo docker exec -it 705c3bb67bce cat /etc/ssl/private/nginx-selfsigned.key, Yes, certificates present. But result of https resuest is: "x509: certificate signed by unknown authority". Maybe I need to restart Nginx inside docker to accept new cetificates, or... I don't know
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.