Using custom certificates
The webserver container has a self-signed certificate obtained from Docker. You may want to replace this certificate with a custom certificate-key pair.
-
Use the docker secret command to tell Docker Swarm the certificate and key by using
WEBSERVER_CUSTOM_CERT_FILEandWEBSERVER_CUSTOM_KEY_FILE. The name of the secret must include the stack name. In the following example, the stack name is 'hub':docker secret create hub_WEBSERVER_CUSTOM_CERT_FILE <certificate file> docker secret create hub_WEBSERVER_CUSTOM_KEY_FILE <key file> -
Add the secret to the webserver service in the
docker-compose.local-overrides.ymlfile:webserver: secrets: - WEBSERVER_CUSTOM_CERT_FILE - WEBSERVER_CUSTOM_KEY_FILE -
Remove the comment character (#) from the
secretssection located at the end of thedocker-compose.local-overrides.ymlfile located in thedocker-swarmdirectory:secrets: WEBSERVER_CUSTOM_CERT_FILE: external: true name: "hub_WEBSERVER_CUSTOM_CERT_FILE" WEBSERVER_CUSTOM_KEY_FILE: external: true name: "hub_WEBSERVER_CUSTOM_KEY_FILE" -
The healthcheck property in the webserver service the
docker-compose.local-overrides.ymlfile must point to the new certificate from the secret:webserver: healthcheck: test: [CMD, /usr/local/bin/docker-healthcheck.sh, 'https://localhost:8443/health-checks/liveness',/run/secrets/WEBSERVER_CUSTOM_CERT_FILE] -
Redeploy the stack by running the following command:
docker stack deploy -c docker-compose.yml -c docker-compose.local-overrides.yml hub
Troubleshooting
If you encounter the following error, follow the steps below:
Error response from daemon: rpc error: code = AlreadyExists desc = secret
hub_WEBSERVER_CUSTOM_CERT_FILE already exists.
-
Stop Black Duck.
docker stack rm hub docker ps : to wait until all containers are down -
Remove previous secrets.
docker secret rm hub_WEBSERVER_CUSTOM_CERT_FILE docker secret rm hub_WEBSERVER_CUSTOM_KEY_FILE -
Create secrets again with new valid ones.
docker secret create hub_WEBSERVER_CUSTOM_CERT_FILE <certificate file> docker secret create hub_WEBSERVER_CUSTOM_KEY_FILE <key file> -
Redeploy Black Duck.
docker stack deploy -c docker-compose.yml -c docker-compose.local-overrides.yml hub -
Wait until all containers are healthy including nginx.
