Skip to content

Instantly share code, notes, and snippets.

@yogendra
Last active March 11, 2024 19:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save yogendra/9535a547a474c3a9970a557b6581060d to your computer and use it in GitHub Desktop.
Save yogendra/9535a547a474c3a9970a557b6581060d to your computer and use it in GitHub Desktop.
Run a Docker Registry with TLS

Run Docker Registry with TLS

There are many instances that I need to do this. Especially if I am installing K8s in an internet restricted environment (example: Install TKG in Internet restricted env)

So I like to use docker registry and mkcert to play with this scenario

  1. Create directories for certs and data

    mkdir -p data certs
  2. Install Mkcert. Just curl and install binary. See project for more instruction

  3. Create CA

    mkcert -install
  4. Copy CA cert into certs directory

    cp  $(mkcert -CAROOT)/rootCA.pem certs/ca.crt
  5. Generate certificate

    mkcert -cert-file certs/registry.crt -key-file certs/registry.key localhost 192.168.1.1 tkg-bootstrap-registry.local
  6. Run docker registry

    docker \
      run \
      -d \
      --restart=always \
      --name registry \
      -v "${pwd}"/data:/var/lib/registry \
      -v "${pwd}"/certs:/certs \
      -e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
      -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.crt \
      -e REGISTRY_HTTP_TLS_KEY=/certs/registry.key \
      -p 443:443 \
      registry:2
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment