Docker Push

Build and push image to a remote Docker registry.

Docker Push step uses Docker registries connected within Microtica Portal to obtain access credentials. If a specific registry name is not provided the default one will be used.

Registry credentials

Credentials for the specified remote Docker registry will be automatically provided by Microtica.

#Syntax

YAML

steps:
  step-name:
    type: docker-push
    title: Build and Push Docker Image
    image_name: microtica/my-app
    tag: latest
    registry: my-registry
ParameterDescriptionRequired
typeThe type of the Microtica built-in step.
Should always be docker-push for this type of step.
Yes
titleThe display name of the step.No
image_nameThe name of the image that will be created and pushed in the remote Docker registry.

When specifying the image name make sure that it is aligned with registry provider naming conventions, otherwise the pipeline execution will fail.
Yes
tagThe tag identifier for the image being pushed.
If not provided, latest tag will be used as default.
No
dockerfilePath to the Dockerfile to be used to build the image.
If not provided, the root path of your source code will be used (./Dockerfile)
No
registryThe name identifier of the Docker registry within Microtica.
If not provided, the default registry will be used.
No
build_contextPath to the context for the Docker build command.
If not provided, the current working dir will be used as Docker build context (docker build -t <image_name> .).
No
build_argumentsArguments to be applied in docker build command.No

#Build and push an image

In the following example we define a pipeline that pulls the code from a Git repository then builds and pushes an image on Docker registry with the name dockerhub.

The image pushed on the remote registry will be named as my-app and tagged with v0.1.0.

microtica.yaml

steps:
  Clone:
    title: Clone my source code from Git
    type: git-clone

  PushDockerImage:
    type: docker-push
    image_name: microtica/my-app
    tag: v0.1.0
    registry: dockerhub

#Custom Dockerfile path and build context

The following example extends the previous one by adding custom path to the Dockerfile. In addition, we have to set the Docker build context to make sure that build command will run in context of app/build path.

microtica.yaml

steps:    
  Clone:
    title: Clone my source code from Git
    type: git-clone

  PushDockerImage:
    type: docker-push
    image_name: microtica/my-app
    tag: v0.1.0
    registry: dockerhub
    dockerfile: app/build/Dockerfile
    build_context: app/build

#Docker build arguments

If you need to provide additional arguments during Docker build-time you can do that by specifying the arguments in build_arguments step property. The arguments will be simply applied in the docker build command.

microtica.yaml

steps:    
  Clone:
    title: Clone my source code from Git
    type: git-clone

  PushDockerImage:
    type: docker-push
    image_name: microtica/my-app
    tag: v0.1.0
    registry: dockerhub
    build_arguments: "--build-arg MIC_PIPELINE_ID --build-arg PACKAGE_URL=https://example.com"

The build arguments can then be used in the Dockerfile file:

Dockerfile

FROM node:latest

ARG MIC_PIPELINE_ID
ARG PORT

RUN curl ${PACKAGE_URL}
RUN echo ${MIC_PIPELINE_ID}

CMD ["node", "index.js"]
Using local variables

You may also use the –build-arg flag without a value, in which case the value from the local environment will be propagated into the Docker container being built.

Arguments lifetime

Arguments allow you to pass the build-time variables that are accessed like regular environment variables in the RUN instruction of the Dockerfile. Also, these values don’t persist in the intermediate or final images like ENV values do.

You must add –build-arg for each build argument.