For MacOS:
$ docker run --rm -it -v /absolute/path/to/your/certificates:/certificates alpine /bin/sh -c "apk add --no-cache openssl && sh"For Windows (assuming you are using PowerShell):
PS> docker run --rm -it -v C:\absolute\path\to\your\certificates:/certificates alpine /bin/sh -c "apk add --no-cache openssl && sh"**Remember to replace '/absolute/path/to/your/certificates' (or 'C:\absolute\path\to\your\certificates' for Windows) with the absolute path to the folder that contains your pem certificate.
Once you are in the Docker container, run the following command:
/ # openssl pkcs12 -export -out /certificates/certificate.p12 -inkey /certificates/YOUR_KEY.pem -in /certificates/YOUR_CERT.pemDon't forget to replace YOUR_KEY.pem and YOUR_CERT.pem with their specific names.
You will be asked to enter the passphrase for your PEM files should they be protected. You'll also need to set a password for the P12 certificate.
After the conversion is done, you can exit the Docker container by typing exit:
/ # exitThe Docker container will automatically be removed, courtesy of the --rm flag we added at the beginning.
Your .p12 file will get saved in your local folder on the host machine, that you mounted while running the Docker container. Verify its presence.
For cleanup, you can optionally remove the Docker Images to free up disk space:
MacOS/Linux:
$ docker rmi -f alpine:latest
$ docker rmi $(docker images -f "dangling=true" -q)
$ docker network pruneWindows (PowerShell):
PS> docker rmi -f alpine:latest
PS> docker rmi $(docker images -f "dangling=true" -q)
PS> docker network prune