DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Hardware-Accelerated OpenGL Rendering in a Linux Container
  • Spinnaker Meets Minikube: Part 1
  • Load-Balancing Minecraft Servers with Kong Gateway
  • Chaos Engineering and Kafka In Action: Topic Level Idempotence and Retry Check

Trending

  • Building a Feature Store With Neo4j and Feast
  • Microsoft Foundry Agent Debugging Dashboard with Microsoft Fabric Eventhouse, KQL, Docker and Grafana
  • AI-Assisted Refinement Preparation
  • Using the Anthropic Evaluation Tool to Check the Claude Code Plugin Efficiency

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Using Docker to Generate SSL Certificates

Using Docker to Generate SSL Certificates

Learn how you can use Docker to generate your SSL certificates, rather than doing it on the host.

By 
Chris Tozzi
·
Oct. 09, 16 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
16.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

When you hear “Docker” and “SSL” you probably assume the conversation is about creating SSL certificates to secure the Docker daemon itself. That’s an important but well-documented task. Or maybe you think we’re talking about creating SSL certificates for use by Dockerized apps. That’s also easy enough if you use various third-party tools (like the ones here and here). But did you know you can also use Docker containers to create SSL certificates for the host?

Using Docker to Generate SSL Certificates

Using Docker to generate SSL certificates is not something that most developers have probably thought of doing. But it’s a neat and handy trick. You may be wondering why you’d ever want to use Docker containers to generate SSL certificates for the host. Couldn’t you just do that on the host itself?

Well, yes. But only if you have the right tools (like OpenSSL) installed on the host. And if you are doing everything you can to keep your Docker server lean, you probably don’t want to add tools like OpenSSL to it, if you don’t have to. Plus, you may not be working from a production Docker server at all, but instead from a Docker test box. If you’re like me, that test box is actually your personal laptop, which probably doesn’t have OpenSSL or other server tools installed on it.

Yes, I could apt-get the openssl package (or apache2-utils) easily enough, but I really don’t want to turn my laptop into a server. Again, I like things to be lean and mean. That’s what makes containers attractive in the first place, after all.

Generating SSL Certificates From Docker Containers

Instead of generating certificates on the host, it’s cool to be able to use Docker containers to create SSL certificates for me. It’s also pretty simple, as the following steps show.

First, of course, you want to pull a container image that supports the creation of SSL certificates using the Docker Hub Nginx image. That image conveniently comes with OpenSSL built-in. (If your image doesn’t contain OpenSSL, you could always add it to the image yourself or, more easily, install it in the container once it starts).

As an example, you’d run:

docker pull nginx

Next, you need to create a private key and certificate signing request with a command like:

docker run -v $PWD:/work -it nginx openssl req -out /work/CSR.csr -new 
-newkey rsa:2048 -nodes -keyout /work/privateKey.key

You’ll now see that the working directory on the host contains the files privateKey.key and CSR.csr. If you want to use them to create a self-signed certificate, you’d run something like:

docker run -v $PWD:/work -it nginx openssl req -x509 -sha256 -nodes 
-days 365 -newkey rsa:2048 -keyout privateKey.key -out 
/work/certificate.crt

And you now have your signed certificate, certificate.crt, in the working directory on the host.

There you have it. You’ve created an SSL certificate using OpenSSL without actually running OpenSSL on the host system.

Going Further

You can do much more using commands like the ones above. In particular, if you want to automate the creation of SSL certificates on Docker for either the Docker host or the container, you could integrate these commands into a Dockerfile, then use that to build SSL certificate generation into the Dockerized app that you create using Codefresh.

So while generating SSL certificates used to be a tedious and repetitive process that required software that you probably don’t have installed on the machine you work from normally, Docker containers make SSL certificate creation fast and easy. In fact, they make it so easy that it’s increasingly hard to have an excuse not to be using SSL certificates for encryption.

Docker (software) Host (Unix) OpenSSL

Opinions expressed by DZone contributors are their own.

Related

  • Hardware-Accelerated OpenGL Rendering in a Linux Container
  • Spinnaker Meets Minikube: Part 1
  • Load-Balancing Minecraft Servers with Kong Gateway
  • Chaos Engineering and Kafka In Action: Topic Level Idempotence and Retry Check

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook