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
devImage
feature to swap out the prod/stable images in runtime using a prebuilt dev-optimized image. - Use the
sync
feature for hot reloading your containers
Workflow
To build, tag and push images with DevSpace, you need to:
- Define your images in the
images
section ofdevspace.yaml
- Call the
build_images
function inside thepipelines
section 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 inCluster
required
InCluster if specified, DevSpace will use BuildKit to build the image within the cluster
inCluster
required name
required string
Name is the name of the builder to use. If omitted, DevSpace will try to create
or reuse a builder in the form devspace-$NAMESPACE
name
required string namespace
required string
Namespace where to create the builder deployment in. Defaults to the current
active namespace.
namespace
required string rootless
required boolean false
Rootless if enabled will create a rootless builder deployment.
rootless
required boolean false image
required string
Image is the docker image to use for the BuildKit deployment
image
required string nodeSelector
required string
NodeSelector is the node selector to use for the BuildKit deployment
nodeSelector
required string noCreate
required boolean false
NoCreate. By default, DevSpace will try to create a new builder if it cannot be found.
If this is true, DevSpace will fail if the specified builder cannot be found.
noCreate
required boolean false noRecreate
required boolean false
NoRecreate. By default, DevSpace will try to recreate the builder if the builder configuration
in the devspace.yaml differs from the actual builder configuration. If this is
true, DevSpace will not try to do that.
noRecreate
required boolean false noLoad
required boolean false
NoLoad if enabled, DevSpace will not try to load the built image into the local docker
daemon if skip push is defined
noLoad
required boolean false createArgs
required string[]
CreateArgs are additional args to create the builder with.
createArgs
required string[] preferMinikube
required boolean false
PreferMinikube if false, will not try to use the minikube docker daemon to build the image
preferMinikube
required boolean false args
required string[]
Args are additional arguments to call docker buildx build with
args
required string[] command
required string[]
Command to override the base command to create a builder and build images. Defaults to ["docker", "buildx"]
command
required string[] docker
required
Docker if docker is specified, DevSpace will build the image using the local docker daemon
docker
required disableFallback
required boolean false
DisableFallback allows you to turn off kaniko building if docker isn't installed
disableFallback
required boolean false preferMinikube
required boolean false
PreferMinikube allows you to turn off using the minikube docker daemon if the minikube
context is used.
preferMinikube
required boolean false useCli
required boolean false
UseCLI specifies if DevSpace should use the docker cli for building
useCli
required boolean false args
required string[]
Args are additional arguments to pass to the docker cli
args
required string[] kaniko
required
Kaniko if kaniko is specified, DevSpace will build the image in-cluster with kaniko
kaniko
required cache
required boolean false
Cache tells DevSpace if a cache repository should be used. defaults to false
cache
required boolean false snapshotMode
required string
SnapshotMode tells DevSpace which snapshot mode kaniko should use. defaults to time
snapshotMode
required string image
required string
Image is the image name of the kaniko pod to use
image
required string initImage
required string
InitImage to override the init image of the kaniko pod
initImage
required string args
required string[]
Args for additional arguments that should be passed to kaniko
args
required string[] command
required string[]
Command to replace the starting command for the kaniko container
command
required string[] namespace
required string
Namespace is the namespace where the kaniko pod should be run
namespace
required string insecure
required boolean false
Insecure allows pushing to insecure registries
insecure
required boolean false pullSecret
required string
PullSecret is the pull secret to mount by default
pullSecret
required string skipPullSecretMount
required boolean false
SkipPullSecretMount will skip mounting the pull secret
skipPullSecretMount
required boolean false nodeSelector
required <nodeSelector_name>:string
NodeSelector is the node selector to use for the kaniko pod
nodeSelector
required <nodeSelector_name>:string tolerations
required object[]
Tolerations is a tolerations list to use for the kaniko pod
tolerations
required object[] serviceAccount
required string
ServiceAccount the service account to use for the kaniko pod
serviceAccount
required string generateName
required string
GenerateName is the optional prefix that will be set to the generateName field of the build pod
generateName
required string annotations
required <annotation_name>:string
Annotations are extra annotations that will be added to the build pod
annotations
required <annotation_name>:string labels
required <label_name>:string
Labels are extra labels that will be added to the build pod
labels
required <label_name>:string initEnv
required <initEnv_name>:string
InitEnv are extra environment variables that will be added to the build init container
initEnv
required <initEnv_name>:string env
required <env_name>:string
Env are extra environment variables that will be added to the build kaniko container
Will populate the env.value field.
env
required <env_name>:string envFrom
required <envFrom_name>:object
EnvFrom are extra environment variables from configmap or secret that will be added to the build kaniko container
Will populate the env.valueFrom field.
envFrom
required <envFrom_name>:object additionalMounts
required object[]
AdditionalMounts are additional mounts that will be added to the build pod
additionalMounts
required object[] secret
required
The secret that should be mounted
secret
required name
required string
Name of the secret in the pod's namespace to use.
More info: https://kubernetes.io/docs/concepts/storage/volumes#secret
+optional
name
required string items
required object[]
If unspecified, each key-value pair in the Data field of the referenced
Secret will be projected into the volume as a file whose name is the
key and content is the value. If specified, the listed keys will be
projected into the specified paths, and unlisted keys will not be
present. If a key is specified which is not present in the Secret,
the volume setup will error unless it is marked optional. Paths must be
relative and may not contain the '..' path or start with '..'.
+optional
items
required object[] ####### key
required string {#images-kaniko-additionalMounts-secret-items-key}
The key to project.
key
required string {#images-kaniko-additionalMounts-secret-items-key}####### path
required string {#images-kaniko-additionalMounts-secret-items-path}
The relative path of the file to map the key to.
May not be an absolute path.
May not contain the path element '..'.
May not start with the string '..'.
path
required string {#images-kaniko-additionalMounts-secret-items-path}####### mode
required integer {#images-kaniko-additionalMounts-secret-items-mode}
Optional: mode bits to use on this file, must be a value between 0
and 0777. If not specified, the volume defaultMode will be used.
This might be in conflict with other options that affect the file
mode, like fsGroup, and the result can be other mode bits set.
+optional
mode
required integer {#images-kaniko-additionalMounts-secret-items-mode}defaultMode
required integer
Optional: mode bits to use on created files by default. Must be a
value between 0 and 0777. Defaults to 0644.
Directories within the path are not affected by this setting.
This might be in conflict with other options that affect the file
mode, like fsGroup, and the result can be other mode bits set.
+optional
defaultMode
required integer configMap
required
The configMap that should be mounted
configMap
required name
required string
Name of the configmap
+optional
name
required string items
required object[]
If unspecified, each key-value pair in the Data field of the referenced
ConfigMap will be projected into the volume as a file whose name is the
key and content is the value. If specified, the listed keys will be
projected into the specified paths, and unlisted keys will not be
present. If a key is specified which is not present in the ConfigMap,
the volume setup will error unless it is marked optional. Paths must be
relative and may not contain the '..' path or start with '..'.
+optional
items
required object[] ####### key
required string {#images-kaniko-additionalMounts-configMap-items-key}
The key to project.
key
required string {#images-kaniko-additionalMounts-configMap-items-key}####### path
required string {#images-kaniko-additionalMounts-configMap-items-path}
The relative path of the file to map the key to.
May not be an absolute path.
May not contain the path element '..'.
May not start with the string '..'.
path
required string {#images-kaniko-additionalMounts-configMap-items-path}####### mode
required integer {#images-kaniko-additionalMounts-configMap-items-mode}
Optional: mode bits to use on this file, must be a value between 0
and 0777. If not specified, the volume defaultMode will be used.
This might be in conflict with other options that affect the file
mode, like fsGroup, and the result can be other mode bits set.
+optional
mode
required integer {#images-kaniko-additionalMounts-configMap-items-mode}defaultMode
required integer
Optional: mode bits to use on created files by default. Must be a
value between 0 and 0777. Defaults to 0644.
Directories within the path are not affected by this setting.
This might be in conflict with other options that affect the file
mode, like fsGroup, and the result can be other mode bits set.
+optional
defaultMode
required integer readOnly
required boolean false
Mounted read-only if true, read-write otherwise (false or unspecified).
Defaults to false.
+optional
readOnly
required boolean false mountPath
required string
Path within the container at which the volume should be mounted. Must
not contain ':'.
mountPath
required string subPath
required string
Path within the volume from which the container's volume should be mounted.
Defaults to "" (volume's root).
+optional
subPath
required string custom
required
Custom if custom is specified, DevSpace will build the image with the help of
a custom script.
custom
required