Run Docker Commands

You can configure a job to run Docker commands on a Docker container when a build runs.

You should use the Docker container for short tests and builds. Don’t run a Docker container for long tests or builds, or the builds might not finish. For example, if you use a Docker image that’s listening on a certain port and behaves like a web server, most likely the build won’t exit.

For more information about Docker commands, see https://docs.docker.com/.

Tip:

If you face a network issue when you run Docker commands, try adding the HTTP_PROXY and HTTPS_PROXY environment variables in the Docker file.

Set Up a VM Build Executor and a Build Executor Template with Docker

Before you can create a build step that uses Docker commands, your organization administrator must create a build executor template that includes the Docker software and add a VM build executor that uses that build executor template. The build executor template can be created from scratch or software can be added to an existing build executor template.

Note:

To find your organization administrator, click Contacts under your user profile. Your administrator, or a list of administrators, will display.

See Create and Manage Build Executor Templates in Administering Visual Builder Studio.

After the organization administrator adds a VM build executor to the build executor template, you can create and configure a job to use that build executor template and add Docker commands.

Configure a Job to Run Docker Commands

Here's how you create and configure a job that runs Docker commands:

  1. Open the job’s configuration page.
    If you're creating a job, in Template in the New Job dialog box, select the Docker build executor template. Proceed to step 4.
  2. Click Settings the Gear icon.
  3. In the Software tab, select the Docker build executor template.
  4. Click Configure Configure.
  5. Click the Steps tab.
  6. From Add Step, select Docker, and then select the Docker command:
    Use this command ... To ...
    login

    Log in to the Docker registry.

    In Registry Host, select a pre-linked Docker registry, or enter the Docker registry’s host name where the images are stored. Leave it empty to use Docker Hub.

    In Username and Password, enter the credentials of the user who can access the Docker registry.

    build

    Build Docker images from a Dockerfile.

    Specify the registry host name, the Docker image name, its version tag, any Docker options, and the name and source of the Dockerfile. You can upload the Dockerfile in the Git repository and provide its path, add the Dockerfile code manually, or provide its URL if it’s available on an external source.

    To specify an external source, include the protocol. For example, include http) in the URL if you’re referencing a remote TAR file, such as http://55.555.555.555/me/mydocker.tar.gz. If you’re referencing a remote repository, ignore the protocol, as in git://github.com/me/my.git#mybranch:myfolder, for example.

    To learn more about Docker build command options, see https://docs.docker.com/engine/reference/commandline/build/.

    tag

    Create a target image tag that refers to the source image.

    Specify the registry host name, Docker image name, and its version tag name for the source and target images.

    push

    Push an image to the Docker registry.

    To learn more about push options, see https://docs.docker.com/engine/reference/commandline/push/.

    images

    List available images.

    To learn more about images, see https://docs.docker.com/engine/reference/commandline/images/.

    save

    Save an image to a .tar archive file.

    In Output File, specify the relative path and name of the output .tar file in the workspace.

    load

    Load an image from a .tar archive file.

    In Output File, specify the relative path and name of the output .tar file in the workspace.

    rmi

    Remove an image. You can remove new images, a specific image, or all images.

    To remove a specific image, enter the host name of the registry where the Docker images are stored. Remember that the images are stored in the registry if they are pushed there. Until the images are pushed, the Registry Host is used to form the fully qualified name of the Docker image on the computer where the image is being created.

    version

    View the version of Docker on the build executor.

  7. Click Save.

The Docker logout command runs automatically after all Docker commands have run.