This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.3.8. Using docker credentials for private registries
You can supply builds with a .docker/config.json file with valid credentials for private container registries. This allows you to push the output image into a private container image registry or pull a builder image from the private container image registry that requires authentication.
For the OpenShift Container Platform container image registry, this is not required because secrets are generated automatically for you by OpenShift Container Platform.
The .docker/config.json file is found in your home directory by default and has the following format:
auths:
https://index.docker.io/v1/:
auth: "YWRfbGzhcGU6R2labnRib21ifTE="
email: "user@example.com"
auths:
https://index.docker.io/v1/:
auth: "YWRfbGzhcGU6R2labnRib21ifTE="
email: "user@example.com"
You can define multiple container image registry entries in this file. Alternatively, you can also add authentication entries to this file by running the docker login command. The file will be created if it does not exist.
Kubernetes provides Secret objects, which can be used to store configuration and passwords.
Prerequisites
-
You must have a
.docker/config.jsonfile.
Procedure
Create the secret from your local
.docker/config.jsonfile:oc create secret generic dockerhub \ --from-file=.dockerconfigjson=<path/to/.docker/config.json> \ --type=kubernetes.io/dockerconfigjson$ oc create secret generic dockerhub \ --from-file=.dockerconfigjson=<path/to/.docker/config.json> \ --type=kubernetes.io/dockerconfigjsonCopy to Clipboard Copied! Toggle word wrap Toggle overflow This generates a JSON specification of the secret named
dockerhuband creates the object.Add a
pushSecretfield into theoutputsection of theBuildConfigand set it to the name of thesecretthat you created, which in the previous example isdockerhub:Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can use the
oc set build-secretcommand to set the push secret on the build configuration:oc set build-secret --push bc/sample-build dockerhub
$ oc set build-secret --push bc/sample-build dockerhubCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can also link the push secret to the service account used by the build instead of specifying the
pushSecretfield. By default, builds use thebuilderservice account. The push secret is automatically added to the build if the secret contains a credential that matches the repository hosting the build’s output image.oc secrets link builder dockerhub
$ oc secrets link builder dockerhubCopy to Clipboard Copied! Toggle word wrap Toggle overflow Pull the builder container image from a private container image registry by specifying the
pullSecretfield, which is part of the build strategy definition:Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can use the
oc set build-secretcommand to set the pull secret on the build configuration:oc set build-secret --pull bc/sample-build dockerhub
$ oc set build-secret --pull bc/sample-build dockerhubCopy to Clipboard Copied! Toggle word wrap Toggle overflow 注意This example uses
pullSecretin a Source build, but it is also applicable in Docker and Custom builds.You can also link the pull secret to the service account used by the build instead of specifying the
pullSecretfield. By default, builds use thebuilderservice account. The pull secret is automatically added to the build if the secret contains a credential that matches the repository hosting the build’s input image. To link the pull secret to the service account used by the build instead of specifying thepullSecretfield, run:oc secrets link builder dockerhub
$ oc secrets link builder dockerhubCopy to Clipboard Copied! Toggle word wrap Toggle overflow 注意You must specify a
fromimage in theBuildConfigspec to take advantage of this feature. Docker strategy builds generated byoc new-buildoroc new-appmay not do this in some situations.