Running Docker Commands to Operate Images
Build on GUI
Add Run Docker Commands, when configuring build actions. Set the parameters according to Table 1.
Parameter |
Description |
---|---|
Action Name |
Assign a custom name to the build action. The name can contain:
|
Tool Version |
Select a tool version that matches your current development environment. For tool versions supported by CodeArts Build, see build tools and versions. If the current tools and versions do not meet your requirements, you can customize a build environment. |
Commands |
Click Add to add a command, and configure it as required. For details about the Docker commands supported by CodeArts Build, see Docker Commands Supported by CodeArts Build. You can drag and drop the commands into the desired execution sequence. |
Build with Code
Modify the code in the BUILD block in Creating a YAML File for Your Code-based Build by referring to the following sample code:
1 2 3 4 5 6 7 |
version: 2.0 # The value must be 2.0. steps: BUILD: - docker: inputs: command: | docker pull swr.xx-xxxxx-x.myxxcloud.com/codeci/dockerindocker:dockerindocker18.09-1.3.2 |
Parameter |
Type |
Description |
---|---|---|
command |
String |
Each command takes up one line. For details about the supported Docker commands, see Docker Commands Supported by CodeArts Build. |
Docker Commands Supported by CodeArts Build
- docker login: Log in to the Docker repository.
Usage: docker login [options] [server]
The following table describes how to set options. server indicates the Docker repository address.Option
Short Form
Description
--password
-p
Password for logging in to the repository.
--username
-u
Username for logging in to the repository.
--password
-stdin
Password obtained from stdin
Example: docker login -u jack -p 12345 mydocker-registry.com
In this example, user jack remotely logs in to the mydocker-registry.com repository using password 12345.
Advanced Usage
To read a password from the file, run cat ~/my_password.txt | docker login --username jack --password-stdin.
- docker build: Build an image from a Dockerfile or context. The context can be a local path (Path) where the build is executed, a remote URL (such as a Git repository, tarball, or text file), or a hyphen (-).
Usage: docker build [options] Path | URL | -
The following table describes how to set options. Path/URL/- indicates the context source.Parameter
Short Form
Description
--file
-f
Dockerfile path. The default value is ./Dockerfile.
--tag
-t
In the format of "Image name:Tag"
Example: docker build -t mydocker-registry.com/org/alpine:1.0 -f ./Dockerfile .
In this example, this command uses the Dockerfile with the tag mydocker-registry.com/org/alpine:1.0 in the current directory to create an image.
- docker push: Push an image to a specified registry.
Usage: docker push [options] name[:tag]
Example: docker push mydocker-registry.com/org/alpine:1.0
In this example, this command pushes tag 1.0 of the mydocker-registry.com/org/alpine image to the remote repository.
- docker pull: Pull an image from a registry.
Usage: docker pull [options] name[:tag|@digest]
The following table describes how to set options.Option
Short Form
Description
--all-tags
-a
Download all tagged images.
Example: docker pull mydocker-registry.com/org/alpine:1.0
In this example, this command pulls the mydocker-registry.com/org/alpine image whose tag is 1.0 from the remote repository.
- docker tag: Modify the tag of the image.
Usage: docker tag source_image[:tag] target_image[:tag]
source_image[:tag] indicates the image whose tag needs to be modified, and target_image[:tag] indicates the target image with a new tag.
Example: docker tag mydocker-registry.com/org/alpine:1.0 mydocker-registry/neworg/alpine:2.0
In this example, this command changes the tag of the mydocker-registry.com/org/alpine image from 1.0 to 2.0.
- docker save: Save one or more images to a .tar file (streamed to the standard output by default).
Usage: docker save [options] image [image...]
The following table describes how to set options.Option
Short Form
Description
--output
-o
Write to a file instead of using standard output.
Example: docker save -o alpine.tar mydocker-registry.com/org/alpine:1.0 mydocker-registry.com/org/alpine:2.0
In this example, this command packages the mydocker-registry.com/org/alpine:1.0 and mydocker-registry.com/org/alpine:2.0 images into alpine.tar.
- docker logout: Log out of a Docker repository.
Usage: docker logout [server]
Example: docker logout mydocker-registry.com
This example indicates that the image repository whose address is mydocker-registry.com is logged out.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot