If you don't specify a Docker image, Space will use the default one. The default image is based on Ubuntu OS and includes Git, curl, Docker, Docker Compose, Kubernetes, Google Cloud support, Open JDK, Python, PHP, .NET SDK, Ruby, Go, Node.js, npm, yarn, and other tools.
You can use this Dockerfile as a basis for creating your own image and hosting it in Space Packages. Learn more
Specify an image for the dev environment
A dev environment runs in a Docker container. If you don't specify an image in a devfile.yaml, Space will use the default image. As a custom image, you can use an image from Docker Hub (or other registries that doesn't require authentication), Space Packages, or create an image from Dockerfile each time a user creates a new dev environment. To specify the image, use the project's devfile.
Image requirements
OS: any glibc-based Linux distribution (for example, CentOS 7+, Debian 9+, Ubuntu 20.04+).
Tools: Git, OpenSSH (if you want to use a remote Git repository), lsof (if you need port forwarding in the IDE).
The container must run as root (there must be no non-root users in Dockerfile).
Container image vs warm-up snapshot
In some cases, you might face a dilemma where to put a certain preparation step: to the container image or to the environment warm-up? For example, your project requires an SDK. To get the SDK, you run curl - o sdk.zip $SDK_URL && unzip sdk.zip. Where do you put this line: to the Dockerfile or to the warm-up script?
Our recommendation:
All additional tools (e.g., the tools installed with apt get) should be installed to the dev environment's image, i.e., described in the Dockerfile.
All binary dependencies stored within the root or the project directory should go to a warm-up script. So, in the example above, the best solution would be to get the SDK in a warm-up script.
In the components.container.image parameter, specify the full image URL.
Important: the Space Packages registry must either belong to the same project where you configure a dev environment or be attached to this project.
A dev environment can use a custom Dockerfile for its container image. The Dockerfile can be located anywhere in the project repository. Note that in this case, Space will build the image each time a user creates a new dev environment. To reduce startup time of the dev environment, we recommend that you build the image once and publish it to the project's Space Packages registry.
Open the project source code and create a Dockerfile, for example, in the docker directory.
Edit the Dockerfile to configure the image.
For example, an image for a Java project:
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
ENV LC_ALL=C.UTF-8
RUN apt-get update
RUN apt-get install -y \
git \
openjdk-11-jdk \
&& rm -rf /var/lib/apt/lists/*
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
Open the project source code and open the project's devfile. If it doesn't exist, create a new one, for example, .space/devfile.yaml.
In the devfile, specify the path to a Dockerfile (uri) and, optionally, to the Docker context (buildContext). You must specify both paths relative to the projectRoot. For example:
schemaVersion: 2.2.0
attributes:
space:
instanceType: large
editor:
type: Idea
components:
- name: image-build
image:
# (Required)
imageName: my-image:latest
dockerfile:
# (Optional) path to Docker context relative to projectRoot
# by default, projectRoot is repository root
buildContext: docker
# (Required) path to Dockerfile relative to projectRoot
uri: docker/Dockerfile
args:
- 'ARG1=A'
- 'ARG2=B'
Commit and push the changes.
You can use images not only from Docker Hub but from any public registry that doesn't require authentication. In case of an image from Docker Hub, you can specify only the image name. For other registries, you must specify the full image URL.
Dev environments can run on three different virtual machine instances: regular (4 vCPUs, 8 GB), large (8 vCPUs, 16 GB), and extra large (16 vCPUs, 32 GB). Learn more about dev environments billing
To specify a default instance type, use the space.instanceType parameter. Users can choose another instance type when creating a dev environment.
schemaVersion: 2.2.0
attributes:
space:
# regular, large, xlarge
instanceType: large
editor:
type: Idea
Set environment variables
To define environment variables in a dev environment container, use the components.container.env parameter.
When creating a new environment, you can view the added variables under Environment variables.
After you push the updated devfile to the project repository, the specified environment variables will be available only in the newly created dev environments.