Pushing an image to an External repository
It is possible to build an image in Rahti and push it to a private external repository. The steps to make it so are:
-
Login into Rahti and, if needed, create a new Rahti project.
-
Create a secret of type
docker-registry
. And link with the Service account that will run the build:oc create secret --docker-server=<url> docker-registry <url> \ --docker-username=<user> --docker-password=<token> oc secrets link builder <url>
- url is the url of the registry. In case of docker hub the value should be
docker.io
, and for GitHub Packages it will beghcr.io
. - user is the username needed to login in the registry.
- password is the password or token. It is recommended to avoid using a password and better use very narrow purpose TOKEN that ideally only allow to push images and nothing else.
- url is the url of the registry. In case of docker hub the value should be
-
Create the build:
oc new-build --binary --to-docker=true \ --to=<image-url>:<tag> \ --name tutorial
- image-url:tag is the url of the image that you are building. It is the same URL that you will later use to pull the image using
docker pull
. - The name can be anything that helps you remember what is this build for.
- image-url:tag is the url of the image that you are building. It is the same URL that you will later use to pull the image using
-
Set the build secret for
push
:oc set build-secret --push bc/tutorial <url>
is the same as in step 2.
Pull private image
If you are building from a private image you can run the same command again replacing
--push
by--pull
-
Test it. You can test the build by running the
oc start-build
command. The directory (.
in the example below), must have aDockerfile
. You can also use the other methods described in the Creating images article.oc start-build tutorial --from-dir=.