image: <image name... || ~>
dockerfile: <relative path>
context: <relative path>
target: <docker stage name>
args:
  <build arg name>: <value>

Building image from Dockerfile is the easiest way to start using werf in an existing project. Minimal werf.yaml below describes an image named example related with a project Dockerfile:

project: my-project
configVersion: 1
---
image: example
dockerfile: Dockerfile

To specify some images from one Dockerfile:

image: backend
dockerfile: Dockerfile
target: backend
---
image: frontend
dockerfile: Dockerfile
target: frontend

And also from different Dockerfiles:

image: backend
dockerfile: dockerfiles/DockerfileBackend
---
image: frontend
dockerfile: dockerfiles/DockerfileFrontend

Naming

Images are declared with image directive: image: <image name>. The image directive starts a description for building an application image. The image name is a string, similar to the image name in Docker:

image: frontend

If image only one in the config, it can be nameless:

image: ~

In the config with multiple, all images must have names:

image: frontend
...
---
image: backend
...

An image can have several names, set as a list in YAML syntax (this usage is equal to describing similar images with different names):

image: [main-front,main-back]

You can use image name for most commands to execute ones for specific image(s):

Also, image name is used for naming when publishing built image into registry (read about it in separate article).

Dockerfile directives

Werf as well as Docker builds the image based on a Dockerfile and a context.

  • dockerfile (required): to set Dockerfile path relative to the project directory.
  • context: to set build context PATH inside project directory (defaults to root of a project, .).
  • target: to link specific Dockerfile stage (last one by default, see docker build –target option).
  • args: to set build-time variables (see docker build –build-arg option).