Updated on 2023-11-28 GMT+08:00

Running Docker Commands

This action aims to run Docker commands on a host to build, push, pull, and run images. The following describes how to configure each command.

login and logout

  1. Search for and add action Run Docker Command.
  2. Select login or logout for Command.

    Only self-hosted and SWR repositories are supported. You are advised to use the action Run Shell Commands to log in to or log out of a public repository.

    When running the login command, retain the default value No for Restart Docker.

    When you log in to a private repository, Docker provides a valid credential of the private repository in the .docker/config.json file. By default, the credential is encoded using Base64. You are advised to use docker-credential-pass and gpg to enhance Docker security.

  3. Select the image repository to be logged in to or logged out of. If no image repository is available, click Create.

    The Create Service Endpoint: Docker repository dialog box is displayed, as shown in the following figure.

    Table 1 Parameters

    Parameter

    Description

    Service Endpoint Name

    Name of the service endpoint to the image repository. The name facilitates service endpoint selection and management.

    Repository Address

    Address of the image repository. You can use a self-hosted or SWR repository.

    NOTE:

    The image repository address cannot contain the organization name or image name.

    The repository address is in the https://XXXX.com or http://XXXX.com format.

    Username

    Username for logging in to the image repository.

    Password

    Password for logging in to the image repository.

  4. Log in to SWR.

    1. Log in to the console. In the upper left corner of the page, choose Service List > Application > SoftWare Repository for Container. On the SWR console, choose My Images > Upload Through Client.
    2. In the displayed dialog box, click Generate a temporary login command.

    3. This topic uses the temporary command as an example. After you click Generate a temporary login command, the following dialog box is displayed.

      • -u is followed by the username.
      • -p is followed by the password.
      • swr.XXXXX.com is the repository address.
    4. On the deployment page, add the service endpoint.

      The repository URL must be in the https://XXXX.com or http://XXXX.com format.

      The image repository address obtained by running the temporary command must be prefixed with https:// or http:.

    5. Click OK.

      Then you can run the login command to log in to the image repository on CodeArts Deploy.

  5. To modify the information about an image repository, click Manage next to Image Repository in the action Run Docker Commands. On the displayed page, edit or delete the repository.

build

Preparations

To create a Docker image, upload the created Dockerfile to the target host in action Select Deployment Source.

Configuration Method

  1. Search for and add action Run Docker Command.
  2. Select the build command, enter the path where the Dockerfile is stored on the target host, and enter the execution parameters of the build command.

tag

  1. Search for and add action Run Docker Command.
  2. Select the tag command, enter the image to be tagged, and set the execution parameters (optional) of the tag command.

    To add tags to multiple groups of images, separate the tags using newline characters.

run

  1. Search for and add action Run Docker Command.
  2. Select the run command and enter the execution parameters of the docker run command.

    When running the run command, you cannot create or start a container in interactive mode. Instead, you must add the -d execution parameter so that the command can run in the background.

Others

  1. Search for and add action Run Docker Command.
  2. Select a command (push, pull, start, stop, restart, rm, or rmi) and enter the execution parameters of the command.

    The command output similar to the following is displayed:

    push: docker.test-registry.com/branch/Ubuntu:v1
    pull: docker.test-registry.com/branch/Ubuntu:v1
    rm: -f db01 db02
    rmi: -f docker.test-registry.com/branch/Ubuntu:v1
    start/stop/restart: container ID or name

    If you encounter any problem during deployment, see Solutions to Common Problems.