DEV Community

Cover image for Use cfssl in a multi-stage build docker image
Mostafa Gazar
Mostafa Gazar

Posted on

1 1

Use cfssl in a multi-stage build docker image

CFSSL is Cloudflare's PKI and TLS toolkit. I recently wanted to use to generate a self signed certificate in a docker file.

You can technically install cfssl in a multitude of ways in whatever docker image you are using. There is a simpler approach though using Docker's multi-stage builds.


Let us say you have a registry image, code below:

FROM registry

LABEL maintainer="mostafa@mlstudioapp.com"
Enter fullscreen mode Exit fullscreen mode

And to use cfssl, you can do something like:

FROM cfssl/cfssl AS cfssl

WORKDIR /

# Generate certificate
COPY ca-csr.json /
RUN cfssl gencert -initca ca-csr.json | cfssljson -bare ca -
RUN rm /ca-key.pem

FROM registry

LABEL maintainer="mostafa@mlstudioapp.com"

# Copy it to the registry
COPY --from=cfssl /ca.csr /certs/selfsigned.crt
COPY --from=cfssl /ca.pem /certs/selfsigned.key
Enter fullscreen mode Exit fullscreen mode

ca-csr.json

{
  "CN": "ML Sutdio CA",
  "hosts": [
    "mlstudio-registry.default.svc.cluster.local"
  ],
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [{
    "C": "NZ",
    "O": "ML Studio"
  }]
}
Enter fullscreen mode Exit fullscreen mode

If you found this helpful spread the word.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay