Skip to main content
Version: v3

odo build-images

odo can build container images based on Dockerfiles/Containerfiles, 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:

- image:
uri: ./Dockerfile
buildContext: ${PROJECTS_ROOT}
name: dockerfile-containerfile-comp

The uri field indicates the relative path of the Dockerfile or Containerfile 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 or Containerfile, 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


odo build-images
$ odo build-images

↪ Building & Pushing Container:
• Building image locally ...
STEP 2/7: WORKDIR /usr/src/app
--> Using cache b18c8d9f4c739a91e5430f235b7beaac913250bec8bfcae531a8e93c750cea87
--> b18c8d9f4c7
STEP 3/7: COPY package*.json ./
--> Using cache cd151181cd9b2c69fc938eb89f3f71d0327d27ffba53c54247a105733cb36217
--> cd151181cd9
STEP 4/7: RUN npm install
--> Using cache 72b79a4f76ab0f9665653a974f5c667b1cb964c89c58e71aa4817b1055b1c473
--> 72b79a4f76a
STEP 5/7: COPY . .
--> 84f475ad011
STEP 6/7: EXPOSE 8080
--> 12af8468cd0
STEP 7/7: CMD [ "node", "server.js" ]
--> 58c0731e9a1
Successfully tagged
✓ Building image locally [2s]

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
$ ODO_IMAGE_BUILD_ARGS='--platform=linux/amd64;--build-arg=MY_ARG=my_value' odo build-images

↪ Building Image: localhost:5000/nodejs-odo-example
• Building image locally ...
[1/2] STEP 1/4: FROM
[1/2] STEP 2/4: RUN echo XXX $MY_ARG
--> Using cache cbd3ef1317b96dbef4c9ab3646df49d3770831516c3b5c9f1e15687d67bc8803
--> cbd3ef1317b9
[1/2] STEP 3/4: COPY package*.json ./
--> Using cache de4a08bf2632ef49339beeda4ba50eb6e8a9b7524ffd5717fdcc372c15003b61
--> de4a08bf2632
[1/2] STEP 4/4: RUN npm install --production
--> Using cache 5a37e2783e140582da7ac4e241790e6e2052826c07f46cc0053801f4580e728c
--> 5a37e2783e14
[2/2] STEP 1/6: FROM
[2/2] STEP 2/6: COPY --from=0 /opt/app-root/src/node_modules /opt/app-root/src/node_modules
--> Using cache 8779f5d3753baec5961b5ae017d8246b2674eb70f3c5607e4060f6b38e07c182
--> 8779f5d3753b
[2/2] STEP 3/6: COPY . /opt/app-root/src
--> 6ea250968b12
[2/2] STEP 4/6: ENV NODE_ENV production
--> 0bf4dd6605e9
[2/2] STEP 5/6: ENV PORT 3000
--> deea4247dd08
[2/2] STEP 6/6: CMD ["npm", "start"]
[2/2] COMMIT localhost:5000/nodejs-odo-example
--> eebc7c012506
Successfully tagged localhost:5000/nodejs-odo-example:latest
✓ Building image locally [4s]

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.