Build an Image with the Dockerfile in root directory

Get started quickly with building Docker images

Building a Docker image is one of the basic operations in Codefresh pipelines.

The source code of the repository is at Feel free to fork it if you want to follow along.

If you don’t have a Codefresh account already, you can easily create a free one from the sign-up page.

Building a Dockerfile from the root folder

By default, if you run a single command like the one below, Docker uses the Dockerfile of the current folder:

docker build . -t my-web-app

You can get the same result within a Codefresh pipeline:


version: '1.0'
    title: Cloning main repository...
    type: git-clone
    repo: 'codefreshdemo/cf-yml-example-build-dockerfile-inroot'
    revision: 'master'
    git: github
    title: Building Node.Js Docker Image
    type: build
    image_name: my-app
    working_directory: '${{main_clone}}'
    tag: 'master'
    dockerfile: Dockerfile

This pipeline checks out the source code of the repository and then builds a dockerfile found at the root folder of the project.

Building a Docker image with a default Dockerfile

Building a Docker image with a default Dockerfile

You can also change the Docker build context by editing the working_directory property. By default, it looks at the root folder of the project, but any subfolder path is also valid.

CI/CD pipeline examples
Build step in pipelines
Build an Image by specifying the Dockerfile location
Build an Image from a different Git repository
Build and push an Image
Build an Image with build arguments