copyright | lastupdated | keywords | subcollection | ||
---|---|---|---|---|---|
|
2024-01-11 |
jobs in code engine, batch jobs in code engine, running jobs with code engine, creating jobs with code engine, images for jobs in code engine, jobs, job run, environment variables, registry secret, registry access secret |
codeengine |
{{site.data.keyword.attribute-definition-list}}
{: #create-job-private}
Create your job that uses an image in a private registry such as private Docker Hub. You can create a job from the console or with the CLI. {: shortdesc}
Before you begin
- To pull images from a private registry, you must first create a private registry. For example, to create a private Docker Hub registry, see Docker Hub documentation{: external}.
- After you create a private registry, push an image to it{: external}.
- You can also set up an access token. By using an access token, you can more easily grant and revoke access to your Docker Hub account without requiring a password change. For more information about access tokens and Docker Hub, see Managing access tokens{: external}.
{: #create-job-private-console}
Create a job configuration that uses an image in a private registry with the {{site.data.keyword.codeengineshort}} console. {: shortdesc}
Before you can work with a {{site.data.keyword.codeengineshort}} job that references an image in a private registry, you must first add access to the registry so {{site.data.keyword.codeengineshort}} can pull the image when the job is run.
- Open the {{site.data.keyword.codeengineshort}}{: external} console.
- Select Let's go.
- Select Job.
- Enter a name for the job; for example,
myjob
. - Select a project from the list of available projects. You can also create a new one. Note that you must have a selected project to create a job.
- Select Container image and click Configure image.
- Enter
docker.io
for Registry server. - For Registry secret, select Create registry secret.
- From the Create registry secret page, choose your registry source. For example, Docker Hub.
- From the Create registry secret page, enter a username. For Docker Hub, it is your Docker ID.
- From the Create registry secret page, enter the password. For Docker Hub, you can use your Docker Hub password or an access token. For more information about access tokens and Docker Hub, see Managing access tokens{: external}.
- Click Create to add the registry secret for {{site.data.keyword.codeengineshort}}.
- From the Configure image page, the registry secret that was added is listed. Select the registry secret for your image.
- Select the namespace and name of the image in Docker Hub for the {{site.data.keyword.codeengineshort}} job to reference. For example, select
mynamespace
and select the imagetestjob
in that namespace. - Select a value for Tag; for example,
latest
. - Click Done. You selected your image in the registry to reference from your job.
- Modify any default values for environment variables or runtime settings. For more information about these options, see Options for creating and running a job.
- From the Create job page, click Create.
- After your job is created, the job page for your specific job opens. From your job page, click Submit job to submit a job based on the current configuration.
To add registry access before you create a job configuration, see Accessing container registries.
{: #create-job-private-cli}
To create a job configuration with an image from a private registry with CLI, use the job create
command. This command requires a name and an image and also allows other optional arguments. For a complete listing of options, see the ibmcloud ce job create
command.
{: shortdesc}
Before you begin
- Set up your {{site.data.keyword.codeengineshort}} CLI environment.
- Create and work with a project.
- Before you can work with a {{site.data.keyword.codeengineshort}} job that references an image in a private registry, you must first add access to the registry, pull the image, and then create your job configuration.
-
To pull images from a private registry, you must first create a private registry. For example, to create a private Docker Hub registry, see Docker Hub documentation{: external}. After you create a private registry, push an image to it{: external}. You can also set up an access token. By using an access token, you can more easily grant and revoke access to your Docker Hub account without requiring a password change. For more information about access tokens and Docker Hub, see Managing access tokens{: external}.
-
Add access to your private registry to pull images. To add access to a private registry with the CLI, use the
ibmcloud ce secret create --format registry
command to create an registry secret. For example, the following command creates registry access to a Docker Hub registry calledprivatedocker
that is athttps://index.docker.io/v1/
and uses your username and password.ibmcloud ce secret create --format registry --name privatedocker --server https://index.docker.io/v1/ --username <Docker_User_Name> --password <Password>
{: pre}
Example output
Creating registry secret 'privatedocker'... OK
{: screen}
-
Create your job configuration and reference the image in your private Docker Hub registry. For example, create the
mytestjob
job configuration to reference thedocker.io/privaterepo/testjob
by using theprivatedocker
access information.ibmcloud ce job create --name mytestjob --image docker.io/privaterepo/testjob --registry-secret privatedocker
{: pre}
The format of the name of the image for this job is REGISTRY/NAMESPACE/REPOSITORY:TAG
where REGISTRY
and TAG
are optional. If REGISTRY
is not specified, the default is docker.io
. If TAG
is not specified, the default is latest
.
{: note}
{: #nextsteps-jobcreatepriv}
-
After you create your job, submit the job to run it. See Run a job. You can run your job multiple times.
-
After you run your job, to view details of your job and job runs, see access job details.
-
Now that your job is created, consider making your jobs event-driven. By using event subscriptions, you can trigger your jobs by periodic schedules or set your job to react to events like file uploads.
-
You can update your job and its referenced code in any of the following ways, independent of how you created or previously updated your job.
-
If you have a container image, per the Open Container Initiative (OCI) standard{: external}, then you need to provide only a reference to the image, which points to the location of your container registry when you create (or update) your job. You can create (or update) your job from images in a public registry or private registry and then access the referenced image from your job run.
If you created your job by using the
job create
command and you specified the--build-source
option to build the container image from local or repository source, and you want to change your job to point to a different container image, you must first remove the association of the build from your job. For example, runibmcloud ce job update -n JOB_NAME --build-clear
. After you remove the association of the build from your job, you can update the job to reference a different image. {: important} -
If you are starting with source code that resides in a Git repository, you can choose to let {{site.data.keyword.codeengineshort}} take care of building the image from your source and creating (or updating) the job with a single operation. In this scenario, {{site.data.keyword.codeengineshort}} uploads your image to {{site.data.keyword.registrylong}}. To learn more, see Creating a job from repository source code. If you want more control over the build of your image, then you can choose to build the image with {{site.data.keyword.codeengineshort}} before you create (or update) your job and run the job.
-
If you are starting with source code that resides on a local workstation, you can choose to let {{site.data.keyword.codeengineshort}} take care of building the image from your source and creating the job with a single CLI command. In this scenario, {{site.data.keyword.codeengineshort}} uploads your image to {{site.data.keyword.registrylong}}. To learn more, see Creating your job from local source code with the CLI. If you want more control over the build of your image, then you can choose to build the image) with {{site.data.keyword.codeengineshort}} before you create (or update) your job and run the job.
For example, you might choose to let {{site.data.keyword.codeengineshort}} handle the build of your local source while you evolve the development of your source for the job. Then, after the image is matured, you can update the job to reference the specific image that you want. You can repeat this process as needed.
When you run your updated job, the latest version of your referenced container image is used for the job run, unless a tag is specified for the image. If a tag is specified for the image, then the tagged image is used for the job run.
-
Looking for more code examples? Check out the Samples for {{site.data.keyword.codeenginefull_notm}} GitHub repo{: external}. {: tip}