MicroticaMicrotica

Docker Push

Build and push a Docker image to a remote registry with the docker-push step. Set the tag, Dockerfile path, build context, build arguments, and image scanning.

Build and push an image to a remote Docker registry.

The Docker Push step uses the Docker registries connected in the Microtica portal to obtain access credentials. If you don't provide a registry name, the default one is used.

Registry credentials

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

Syntax

microtica.yaml
steps:
  step-name:
    type: docker-push
    title: Build and Push Docker Image
    image_name: microtica/my-app
    tag: latest
    registry: my-registry
ParameterDescriptionRequired
titleThe display name of the step.No
typeThe type of the Microtica built-in step.
Should always be docker-push for this type of step.
Yes
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.

Default: latest
No
dockerfilePath to the Dockerfile to be used to build the image.

Default: ./Dockerfile
No
registryThe name identifier of the Docker registry within Microtica.

Default: default registry from the Microtica Portal
No
build_contextPath to the context for the Docker build command.

Default: .
docker build -t <image_name> .
No
build_argumentsArguments to be applied in docker build command.No
scanEnable image vulnerability scanning.

Default: true
No

Build and push an image

The example below defines a pipeline that pulls the code from a Git repository, then builds and pushes an image to the Docker registry named dockerhub.

The pushed image is named my-app and tagged 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

This example extends the previous one with a custom path to the Dockerfile. It also sets the Docker build context so that the build command runs in the context of the 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

To pass extra arguments at Docker build time, set them in the build_arguments step property. The arguments are applied directly to 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"

You can then use the build arguments in the Dockerfile:

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 let you pass build-time variables that are accessed like regular environment variables in the RUN instruction of the Dockerfile. These values don't persist in the intermediate or final images the way ENV values do.

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

Next steps

On this page