Single/Double Container Mode
About 592 wordsAbout 2 min
Cloud-native development can be launched in two modes:
- Single Container Mode: Development environment and code service (
code-server
) are in the same container - Double Container Mode: Development environment and code service (
code-server
) are in two different containers, with the workspace (/workspace
) directories shared between the two containers
Development Environment: This can be understood as a user-customized development environment container (configured via .ide/Dockerfile
or a custom image), or the default container environment provided by CNB. It includes software installed by the user or pre-installed by default.
Single Container Mode
Single container mode is recommended. The following methods start in single container mode:
Starting with Default Configuration
When users haven't made any configurations (i.e., haven't configured startup pipeline and .ide/Dockerfile
), the development environment starts with default configuration. The default development environment has both code-server
service and ssh
service installed, so it will start in single container mode, supporting both WebIDE and VSCode remote development.
See documentation for details.
Starting with Custom Configuration
When users have configured a startup pipeline or .ide/Dockerfile
, and the custom image or .ide/Dockerfile
has code-server
service installed, the development environment and code-server
service are in the same container, which will start in single container mode.
The following three methods (all development environment images have code-server service installed) start in single container mode:
- Specifying development environment via Docker image
- Customizing development environment via Dockerfile
- Customizing both development environment and startup process
Double Container Mode
When the development environment container doesn't have code-server service installed, we will start an additional code-server
container as the code service container, to support WebIDE
and VSCode
client access to the development environment, i.e., double container mode. The workspace (/workspace
) directories of the two containers are shared.
The following two methods will start in double container mode:
Docker Image Without code-server Installed
# .cnb.yml
$:
vscode:
# Docker image without code-server service installed
- docker:
image: node:22
services:
- vscode
- docker
# Tasks to execute after the development environment starts
stages:
- name: ls
script: ls -al
Custom Dockerfile Without code-server Installed
# .ide/Dockerfile
# You can replace node with your required base image
FROM node:20
# Install software as needed
RUN apt-get update && apt-get install -y git wget unzip openssh-server
# Specify character set to support Chinese input in command line (choose character set as needed)
ENV LANG C.UTF-8
ENV LANGUAGE C.UTF-8
Double Container Mode - Cross-Container Terminal
In double container mode, when accessing WebIDE or VSCode, you're actually accessing the code-server
container.
So how do you access the development environment container from the editor?
We've added an extra cross-container terminal in the code-server
container. In WebIDE or VSCode client, when you open a terminal, the default terminal is one that can access the development environment container across containers. This terminal is named CNB
.
If the development environment container doesn't support git commands, you can switch to other terminals not named CNB
to use the terminal built into code-server for git operations.
Double Container Mode - Plugin Capability Limitations
In double container mode, when accessing WebIDE
or VSCode
, the installed VSCode plugins are in the code-server container, which may not be able to implement capabilities like Debug that need to access the development environment container.