Skip to main content
Version: 5.14

Configure Terminal

There are two main modes how to develop with DevSpace, by streaming the log output of pods in DevSpace or by opening a terminal to the pod you would like to develop with. If you prefer the latter, you can configure the dev.terminal option to tell DevSpace to open a terminal to a target container.

In the dev.terminal section in the devspace.yaml you can configure the terminal:

images:
frontend:
image: myregistry/appfrontend
dependencies:
- name: backend
source:
path: backend
deployments:
- name: frontend
helm:
componentChart: true
values:
containers:
- image: myregistry/appfrontend
command: ["sleep"]
args: ["999999999"]
dev:
terminal:
imageSelector: myregistry/appfrontend
workDir: '/path/to/my/workdir'
# If you would like to open a different shell or start
# it with a different command you can also use
command: ["bash"]
Sleeping Container

You will need to make sure that the container has a terminal equipped and is sleeping so that you can start your application.

Configuration#

imageSelector#

The imageSelector option expects a string that specifies an image (e.g. my-registry.com/lib/my-image:tag) to select a target pod and container with. The newest running pod that has a container which matches this image will be selected by DevSpace.

In addition, you can also reference images from the images section in the imageSelector with:

  • If the image in imageSelector matches a images.*.image, DevSpace will automatically append the latest built tag during runtime to the imageSelector.
  • You can also let DevSpace resolve the target image and tag by using the helpers image() or tag()

For example:

images:
app:
image: my-registry.com/lib/my-image
dev:
...
# DevSpace will search for the newest pod with a container that
# uses my-registry.com/lib/other-image:latest
- imageSelector: my-registry.com/lib/other-image:latest
# DevSpace will search for the newest pod with a container that
# uses my-registry.com/lib/my-image:xxxxx (latest built tag by DevSpace)
- imageSelector: my-registry.com/lib/my-image
# DevSpace will search for the newest pod with a container that
# uses my-registry.com/lib/my-image:custom-tag
- imageSelector: image(my-registry.com/lib/my-image):custom-tag
# DevSpace will search for the newest pod with a container that
# uses my-registry.com/lib/my-image:custom-tag
- imageSelector: image(app):custom-tag
# DevSpace will search for the newest pod with a container that
# uses my-registry.com/lib/my-image:xxxxx (latest built tag by DevSpace)
- imageSelector: image(app):tag(app)
# DevSpace will search for the newest pod with a container that
# uses the image of app of dependency dep1 with the latest built tag by DevSpace
- imageSelector: image(dep1.app):tag(dep1.app)

imageName#

The imageName option expects a string with the name of an image from the images section of the devspace.yaml. Using imageName tells DevSpace to select the container based on the referenced image that was last built using DevSpace.

info

You can convert a value in imageName to imageSelector by converting the value of imageName to image(my-image):tag(my-image). For example, the image name imageName: my-image would be equal to the image selector: imageSelector: image(my-image):tag(my-image). We encourage people to prefer imageSelector instead of imageName, because imageSelector is a lot more flexible and you can also select images that are not defined in images.

note

When you want to select a container with an image that is not defined in your devspace.yaml, you generally want to select the right pod using the imageSelector or labelSelector.

note

You can also select an image from a dependency with dependency1.image1

Example: Setting imageName#

images:
frontend:
image: myregistry/appfrontend
backend:
image: myregistry/appbackend
deployments:
- name: backend
helm:
componentChart: true
values:
containers:
- image: myregistry/appbackend
- name: frontend
helm:
componentChart: true
values:
containers:
- image: myregistry/appfrontend
command: ["sleep"]
args: ["999999999"]
dev:
terminal:
imageName: backend

labelSelector#

The labelSelector option expects a key-value map of strings with Kubernetes labels. This can be used to select the correct target pod with labels instead of the image name like imageSelector or imageName. If the pod you want to select has multiple containers, make sure to use containerName as well.

Example: Setting labelSelector#

dev:
terminal:
labelSelector:
app: my-app
# If the pod has multiple containers make sure to set this
containerName: container1

containerName#

If you select a pod via labelSelector and the pod has multiple containers, you'll need to specify a container name with this option.

namespace#

If this option is specified DevSpace will search the pod in this namespace.

workDir#

If this option is specified DevSpace will open the shell in the specified working directory.

command#

The command option expects a string array as optional configuration for how to open the shell for terminal forwarding. If this option is specified, workDir will not work anymore.

Command Termination

If command is a non-interactive command that terminates, DevSpace will run the command and exits after the command has terminated.