Skip to main content
Version: 1.47

Build your container images with Okteto

The build section of the Okteto Manifest lists the container images of your application. okteto build builds them in your cluster with the Okteto Build Service and pushes them to the Okteto Registry, so you don't need Docker on your machine.

This page uses the Movies app. Run the commands from the root of your local copy, as described in the requirements of the series.

The build Section​

The build section of the Movies app defines four images, two per service:

okteto.yaml
build:
api-dev:
context: api
target: dev

api:
context: api
target: prod
depends_on:
- api-dev

frontend-dev:
context: frontend
target: dev

frontend:
context: frontend
target: prod
depends_on:
- frontend-dev

Each key is the name of an image. context is the folder that Okteto sends to the Build Service, which builds the Dockerfile it finds there. target selects one of the stages of that Dockerfile:

  • dev: the development image. It contains Node.js, the dependencies that npm ci installs from package-lock.json, and the source code. Test and Develop use it.
  • prod: the application image that the Helm chart deploys.

depends_on makes Okteto build the development image first, so the application image reuses its cached layers. In frontend/Dockerfile, the dev stage builds the application and the prod stage copies the result into an nginx image:

frontend/Dockerfile
FROM node:26.13.1-trixie-slim AS dev

WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM nginx:1.30.7-alpine AS prod

COPY --from=dev /usr/src/app/dist /usr/share/nginx/html
EXPOSE 80

The build reference lists the other fields of an image, such as dockerfile and args.

Building the Images​

Build the four images:

okteto build
i Using cindy @ okteto.example.com as context
i Building '/Users/cindy/getting-started/api/Dockerfile'...
...
✓ Image 'registry.okteto.example.com/cindy/getting-started-api-dev:okteto' successfully pushed
i Building '/Users/cindy/getting-started/frontend/Dockerfile'...
...
✓ Image 'registry.okteto.example.com/cindy/getting-started-frontend-dev:okteto' successfully pushed
i Building '/Users/cindy/getting-started/api/Dockerfile'...
...
✓ Image 'registry.okteto.example.com/cindy/getting-started-api:okteto' successfully pushed
i Building '/Users/cindy/getting-started/frontend/Dockerfile'...
...
✓ Image 'registry.okteto.example.com/cindy/getting-started-frontend:okteto' successfully pushed

Okteto names each image after the repository and its key in the build section (getting-started-api), and pushes it to your Namespace in the Okteto Registry with the okteto tag. To build a single image, name it: okteto build api.

With Smart Builds, Okteto skips an image whose context hasn't changed since its last build. In that case, okteto build prints:

i Okteto Smart Builds is skipping build of "api" because it's already built from cache.

To build the images again anyway, run okteto build --no-cache.

Image Variables​

After a build, Okteto stores the reference of each image in an OKTETO_BUILD_<IMAGE>_IMAGE variable, with dashes turned into underscores. For the Movies app, they are OKTETO_BUILD_API_IMAGE, OKTETO_BUILD_FRONTEND_IMAGE, OKTETO_BUILD_API_DEV_IMAGE, and OKTETO_BUILD_FRONTEND_DEV_IMAGE. The deploy section passes the application images to Helm, so your application runs the code you have on your machine, and the test and dev sections use the development images. Each image has other built-in variables too.

okteto deploy also builds the images that aren't built yet, so you can deploy without running okteto build first.

Your images are now in the Okteto Registry, built from your local code. In the next step, deploy the Movies app with them.