Authoring devfiles - Components
Adding a container component
To incorporate custom tools into the workspace, define an image-based configuration of a container in a workspace using the container
component type.
Prerequisites
Procedure
Define a component using the type
container
.A container component
devfile.yamlcomponents: - name: maven container: image: eclipse/maven-jdk8:latest volumeMounts: - name: mavenrepo path: /root/.m2 env: - name: ENV_VAR value: value endpoints: - name: maven-server targetPort: 3101 protocol: https secure: 'true' exposure: public memoryRequest: 256M memoryLimit: 1536M cpuRequest: 0.1 cpuLimit: 0.5 command: ['tail'] args: ['-f', '/dev/null']
A minimal container component
devfile.yamlschemaVersion: 2.2.0 metadata: name: mydevfile components: - name: go container: image: golang memoryLimit: 512Mi command: ['sleep', 'infinity']
Specify the type of component using the
container
property. Use theimage
property to specify the image for the component. When defining theimage
, use container naming conventions. For example, theimage
property in the preceding example refers to the container image,docker.io/library/golang:latest
.Use the
container
component to augment the image with additional resources and information. This component allows you to integrate the tooling provided by the image with the application that consumes the devfile.Mounting project sources
For the
container
component to have access to the project sources, you must set themountSources
attribute totrue
.devfile.yamlschemaVersion: 2.2.0 metadata: name: mydevfile components: - name: go container: image: golang memoryLimit: 512Mi mountSources: true command: ['sleep', 'infinity']
The sources are mounted on a location stored in the
PROJECTS_ROOT
environment variable that is made available in the running container of the image. This location defaults to/projects
. IfsourceMapping
is defined in the container, it overrides thePROJECT_ROOT
value and mounts the source to the path defined bysourceMapping
.Specify a volume
For the
container
component to have a shared volume, you must define a volume component in the devfile and reference the volume usingvolumeMount
in container component. For more information on volume component, see adding a volume component.devfile.yamlcomponents: - name: mycontainer container: image: java11-maven:next memoryLimit: 768Mi mountSources: true volumeMounts: - name: m2 path: /home/user/.m2 - name: m2 volume: size: 1Gi
Container Entrypoint
Use the
command
attribute of thecontainer
type to modify theentrypoint
command of the container created from the image. The availability of thesleep
command and the support for theinfinity
argument depend on the base image used in the particular images.All tools will respect the specified
command
. Whencommand
is not defined, the container will use the default from the image specified. Whencommand
is defined, it will override the one present in the image as intended. Either thecommand
defined by the image or by the container component within the devfile must be non-terminating, such as the case of settingcommand
tosleep
with theinfinity
argument.devfile.yamlcomponents: - name: go container: image: golang memoryLimit: 512Mi mountSources: true command: ['sleep', 'infinity']