Build and Push an Image

Using this repository we’ll help you get up to speed with basic functionality such as: building Docker images and pushing.

This project uses Node JS to build an application which will eventually become a distributable Docker image.

Looking around

In the root of this repository you’ll find a file named codefresh.yml, this is our build descriptor and it describes the different steps that comprise our process.

In this example, the push-the-image step references the image built by the build-the-image step, using the candidate attribute. Make sure to configure your account’s Docker registry details and credentials before you execute a push.

codefresh.yml

version: '1.0'

steps:

  build_image:
    title: Building Voting Image
    type: build
    #Important: rename this image to to a valid repository in your registry. For example: myUserName/vote
    image_name: codefresh/vote
    #The directory should be relative to git repository that is used for cloning
    working_directory: ${{main_clone}}
    #Dockerfile location should be relative to the working directory
    dockerfile: Dockerfile

  push_to_registry:
    title: Pushing to Docker Registry (with credentials)
    type: push

    #A candidate is the image that we want to push to registry
    candidate: '${{build_image}}'

    # You can push the image with whatever tag you want. In our example we use CF_BRANCH, which is a variable in
    # the build process, accessible throughout the entire flow.
    tag: '${{CF_BRANCH}}'

    #uncomment the registry and add your own registry if you want to use any registry other than dockerhub. See docs.codefresh.io for more information
    #registry:
    credentials:
      #make sure that you have a dockerUsername and dockerPassword define on the pipeline.
      username: '${{dockerUsername}}'
      password: '${{dockerPassword}}'
Example

Just head over to the example repository in Github and follow the instructions there.

For more information about the fields for the push-the-image step, see.

Push to Dockerhub

If you want to push your image to Dockerhub, change the myuser field for your image-name on your name of Dockerhub account.

Docker registries

You can integrate with other docker registries . If you want to push your image to Dockerhub, change the myuser field for your image-name on your name of Dockerhub account.

After adding this repository as new service to codefresh, go to pipelines of this service and provide your dockerhub credentials as environment variables.

codefresh_push_credentials.png

If your credentials are correct you can see that the created image was pushed to your dockerhub account

codefresh_push_credentials.png