odo build-images
odo
can build container images based on Dockerfiles, and push these images to their registries.
When running the command odo build-images
, odo
searches for all components in the devfile.yaml
with the image
type, for example:
components:
- image:
imageName: quay.io/myusername/myimage
dockerfile:
uri: ./Dockerfile
buildContext: ${PROJECTS_ROOT}
name: component-built-from-dockerfile
The uri
field indicates the relative path of the Dockerfile to use, relative to the directory containing the devfile.yaml
.
As indicated in the Devfile specification, uri
could also be an HTTP or HTTPS URL.
The buildContext
indicates the directory used as build context. The default value is ${PROJECT_SOURCE}
.
For each image component, odo
executes either podman
or docker
(the first one found, in this order), to build the image with the specified Dockerfile, build context and arguments.
If the --push
flag is passed to the command, the images will be pushed to their registries after they are built.
Running the command
Pre-requisites
- Login to an image registry (quay.io, hub.docker.com, etc)
- Dockerfile
odo build-images
Example
Passing extra args to Podman or Docker
You can set the ODO_IMAGE_BUILD_ARGS
environment variable,
which is a semicolon-separated list of extra arguments to pass to Podman or Docker when building images.
A typical use case for this is to build images for a platform different from the one odo
is running on.
For example, building images on Mac with Apple Silicon, with the intent to use them on a cluster supporting a different architecture or operating system.
ODO_IMAGE_BUILD_ARGS='arg1=value1;arg2=value2;...;argN=valueN' odo build-images
Example
Faking the image build
You can also fake the image build by exporting PODMAN_CMD=echo
or DOCKER_CMD=echo
to your environment. Read environment variables controlling odo
behaviour for more information.
Substituting variables
The Devfile can define variables to make the Devfile parameterizable. The Devfile can define values for these variables, and you
can override the values for variables from the command line when running odo build-images
, using the --var
and --var-file
options.
See Substituting variables in odo
dev for more information.