Image Registry
NotesIt’s one thing building container images and running them locally, but the core reason for working with containers is to ship them around. This is done by tagging images and pushing them to image registries, from where platforms such as OpenShift can pull them.
A project#
Everything in OpenShift lives in a project (a Kubernetes namespace with some extras). Create one for the application:
oc new-project example-for-youoc now uses this project for every command. (On the Developer Sandbox, you can’t create projects: use the one you’re given, and replace example-for-you with its name in the image paths below.)
Pushing to OpenShift’s registry#
Find the address of the registry’s route:
oc get route default-route -n openshift-image-registry --template='{{ .spec.host }}'default-route-openshift-image-registry.apps-crc.testingLog Podman in to the registry, using your OpenShift user name and a token from your oc login:
podman login -u $(oc whoami) -p $(oc whoami -t) --tls-verify=false default-route-openshift-image-registry.apps-crc.testingLogin Succeeded!--tls-verify=false is needed because OpenShift Local uses a self-signed certificate. Never use it with a real registry.
An image’s name says where it lives: the registry, the project, the image name and a tag. Tag the local image with that name:
podman tag localhost/example-for-you:1.0.0 default-route-openshift-image-registry.apps-crc.testing/example-for-you/example-for-you:1.0.0And push it:
podman push --tls-verify=false default-route-openshift-image-registry.apps-crc.testing/example-for-you/example-for-you:1.0.0OpenShift records pushed images as an image stream. You can see it with:
oc get imagestreamsNAME IMAGE REPOSITORY TAGS UPDATED
example-for-you default-route-openshift-image-registry.apps-crc.testing/example-for-you/example-for-you 1.0.0 39 seconds agoInside the cluster, the same registry is at image-registry.openshift-image-registry.svc:5000, which is the address the Deployment in the next section uses.
You can also push to an external registry such as Quay.io or GitHub’s container registry, and have OpenShift pull from there. That’s what you’d use on the Developer Sandbox, where you can’t use the built-in registry’s route. For a private repository, OpenShift needs a pull secret: see oc create secret docker-registry --help.
Use a new tag, such as 1.0.1, for each version you push, rather than reusing latest. That way you always know exactly which version is running, and can go back to the previous one.