Image Building
DevSpace can build, tag and push images using a variety of build engines.
Because image building can waste a lot of time and slows down developers, we recommend that you only build images when running DevSpace in your CI/CD pipelines using devspace build/deploy but not when a developer runs devspace dev.
Instead of image building, use the following workflow for devspace dev:
- Deploy your application using prod/stable images
- Use the
devImagefeature to swap out the prod/stable images in runtime using a prebuilt dev-optimized image. - Use the
syncfeature for hot reloading your containers
Workflow
To build, tag and push images with DevSpace, you need to:
- Define your images in the
imagessection ofdevspace.yaml - Call the
build_imagesfunction inside thepipelinessection ofdevspace.yaml - Execute the respective pipeline
1. Define images
Define as many images as need in your devspace.yaml:
images:
backend:
dockerfile: ./Dockerfile
frontend:
dockerfile: ./frontend/Dockerfile
context: ./frontend
other: ...
2. Call build_images in Pipeline
- Build All Images
- Build Single Image
- Build Multiple Images
pipelines:
build:
run: |
build_images --all
pipelines:
build:
run: |
build_images backend
pipelines:
build:
run: |
build_images backend frontend
3. Run Pipeline
Any of the pipelines shown above can be executed via:
devspace build(shortcut)devspace run-pipeline build(long form)
Config Reference
images required <image_name>:object
Images holds configuration of how DevSpace should build images. By default, DevSpace will build all defined images.
If you are using a custom pipeline, you can dynamically define which image is built at which time during the
execution.
images required <image_name>:object <image_name> required string
Name of the image, will be filled automatically
<image_name> required string image required string
Image is the complete image name including registry and repository
for example myregistry.com/mynamespace/myimage
image required string tags required string[]
Tags is an array that specifies all tags that should be build during
the build process. If this is empty, devspace will generate a random tag
tags required string[] dockerfile required string ./Dockerfile
Dockerfile specifies a path (relative or absolute) to the dockerfile. Defaults to ./Dockerfile.
dockerfile required string ./Dockerfile context required string ./
Context is the context path to build with. Defaults to the current working directory
context required string ./ buildArgs required <buildArg_name>:string
BuildArgs are the build args that are to the build
buildArgs required <buildArg_name>:string target required string
Target is the target that should get used during the build. Only works if the dockerfile supports this
target required string network required string
Network is the network that should get used to build the image
network required string rebuildStrategy required string default default
always
ignoreContextChanges
RebuildStrategy is used to determine when DevSpace should rebuild an image. By default, devspace will
rebuild an image if one of the following conditions is true:
- The dockerfile has changed
- The configuration within the devspace.yaml for the image has changed
- A file within the docker context (excluding .dockerignore rules) has changed
This option is ignored for custom builds.
rebuildStrategy required string default defaultalways
ignoreContextChanges
entrypoint required string[]
Entrypoint specifies an entrypoint that will be appended to the dockerfile during
image build in memory. Example: ["sleep", "99999"]
entrypoint required string[] cmd required string[]
Cmd specifies the arguments for the entrypoint that will be appended
during build in memory to the dockerfile
cmd required string[] appendDockerfileInstructions required string[]
AppendDockerfileInstructions are instructions that will be appended to the Dockerfile that is build
at the current build target and are appended before the entrypoint and cmd instructions
appendDockerfileInstructions required string[] skipPush required boolean false
SkipPush will not push the image to a registry if enabled. Only works if docker or buildkit is chosen
as build method
skipPush required boolean false createPullSecret required boolean true
CreatePullSecret specifies if a pull secret should be created for this image in the
target namespace. Defaults to true
createPullSecret required boolean true buildKit required
BuildKit if buildKit is specified, DevSpace will build the image either in-cluster or locally with BuildKit
buildKit required docker required
Docker if docker is specified, DevSpace will build the image using the local docker daemon
docker required kaniko required
Kaniko if kaniko is specified, DevSpace will build the image in-cluster with kaniko
kaniko required custom required
Custom if custom is specified, DevSpace will build the image with the help of
a custom script.
custom required 