Manage sub-containers with DockerBoard

Updated at:

DSW sub-containers are built on Docker-in-Docker (DinD) technology. Within a single DSW instance, you can create and manage multiple secondary containers to isolate environments and resources. The PAI console provides a visual interface for creating, starting, stopping, and deleting sub-containers, and for accessing them over SSH.

Use cases

  • Isolate different development environments within the same DSW instance and compare training results across images.

  • When GPU resources are tight, create sub-containers from different images to switch runtimes, without rebuilding the instance and waiting in the queue again.

  • When multiple developers share a DSW instance, use sub-containers to isolate each developer's environment and resources.

Prerequisites

  • Sub-containers are currently supported only on DSW instances created on a Lingjun resource group or a public resource group.

  • The instance administrator (the user who created the instance, or the owner) must have the permissions to create and manage DSW instances.

  • The Enable Multi-Container Isolation (DinD) feature must be enabled when the DSW instance is created.

  • To access sub-containers over SSH, also enable the SSH feature on the DSW instance.

Roles and permissions

Sub-container management involves two roles:

  • Instance administrator (owner): The user who created the DSW instance. This role manages instance-level configuration, including enabling DinD, configuring access restrictions, setting the maximum number of sub-containers, and defining data directory isolation rules.

  • Sub-container developer: A user who has a corresponding workspace role (such as algorithm development) or RAM permissions. Sub-container developers can view the sub-container list, create their own sub-containers, and use them by logging on over SSH. Each developer can start, stop, and delete only the sub-containers they created, but can view the information of all sub-containers.

Permissions can be controlled in two ways:

  • Workspace role-based: The instance administrator can restrict specific roles (such as algorithm development) from accessing the main container in the instance configuration. Restricted roles can develop only in sub-containers. This method is easy to understand and fits most scenarios.

  • RAM policy-based: Configure RAM policies for finer-grained permission control, down to specific sub-containers on specific instances. This method suits enterprise customers that require stricter permission control.

Instance administrator operations

Enable multi-container isolation when creating an instance

  1. Log on to the PAI console, go to the DSW page, and click Create Instance.

  2. In the instance configuration, find the Enable Multi-Container Isolation (DinD) switch and turn it on.

  3. After you enable it, the following parameters appear:

    • Restrict roles that can access the main container: Select the workspace roles to restrict from the drop-down list. Restricted roles cannot open or operate the DSW main container directly. Instead, they develop in sub-containers that they access over SSH.

      For example, after you select Algorithm Development, users with the algorithm development role cannot enter the main container, but they can still create and use their own sub-containers on the Sub-container Management tab of the instance details page.

      If you don't select any role, all authorized users can access the main container, and the behavior stays the same as before.

    • Maximum Number of Sub-containers: Set the maximum number of sub-containers that can be created on the instance. Valid values are integers from 1 to 16, and the default value is 10.

    • Data Catalog Fencing Configuration: Specify the path of the data directory isolation configuration file in the main container. The default path is /etc/docker/dockerboard/mount_access.json. This file controls the data directories that each user can mount when creating sub-containers. You can first click Configuration Template Download to download the configuration file template. For the configuration steps, see Configure data directory isolation.

  4. Complete the remaining instance configuration and submit it to create the instance.

Configure data directory isolation

Data directory isolation controls the data directories in the main container that each developer can mount when creating a sub-container. It prevents developers from accessing the storage data of other users without authorization.

Configuration steps:

  1. On the instance creation or edit page, click the Configuration Template Download link under Data Catalog Fencing Configuration to download the JSON template file.

  2. Follow the template format and fill in the mapping between each Alibaba Cloud RAM user UID and the directories in the DSW main container that the user can access.

  3. Place the edited mount_access.json file in the DSW main container at the location specified by the configured path (by default, /etc/docker/dockerboard/mount_access.json).

Configuration file format:

The configuration file is in JSON format. Each key is the UID of an Alibaba Cloud RAM user, and each user entry supports two fields: Allow (the directories the user is allowed to mount) and Deny (the directories the user is not allowed to mount). The following example shows the format:

{
  "123124432xxx": {
    "Allow": [
      "/mnt/workspace",
      "/mnt/data1"
    ],
    "Deny": [
      "/mnt/data2"
    ]
  },
  "224321234xxx": {
    "Allow": [
      "*"
    ]
  }
}

The following table describes the fields:

Field

Description

key (for example, 123124432xxx)

The UID of an Alibaba Cloud RAM user

Allow

The list of main container directories that the user is allowed to mount. Set this field to "*" to allow all directories to be mounted

Deny

The list of main container directories that the user is not allowed to mount. Deny takes precedence over Allow. If a directory appears in both lists, it cannot be mounted. This field is optional

Configuration rules:

  • If the configuration file exists and is in valid format, the system checks whether the current user has permission to mount the selected directories when a sub-container is created.

  • If the configuration file contains no entry for the current user, the user cannot mount data directories when creating a sub-container, and the following message is displayed: "Your account has no available DSW paths. If you need to mount directories, contact the instance administrator to add the configuration for you."

  • If the configured file path is empty or the file doesn't exist, the system skips directory isolation checks, and all users can mount any directory in the main container.

Sub-container developer operations

Open the sub-container management page

  1. Log on to the PAI console and go to the DSW page.

  2. In the instance list, click the name of the target instance on which DinD is enabled to go to the instance details page.

  3. On the instance details page, click the Sub-container Management tab to open the management page.

Note

The sub-container management tab appears only when the DSW main container is in the Running state. If the main container isn't running, the tab isn't displayed.

Create a sub-container

On the sub-container management page, click the Create Sub-container button and complete the following settings in the creation form.

Basic information

Parameter

Required

Description

Example

Container name

Yes

Specify a name that makes the sub-container easy to identify.

For example: my-container

Hostname

No

Specify a custom hostname for the sub-container.

For example: my-host

Restart policy

No

Set the automatic restart policy for the container after it exits.

For example: no automatic restart

Environment information

Parameter

Required

Description

Example

Image configuration

Yes

Select the image used by the sub-container. Two methods are supported:

  • Custom image: select a custom image that is registered with PAI.

  • Image address: enter the complete address of the image repository. If the image repository is private, you must provide the credentials.

For example: dsw-registry-vpc.cn-hangzhou.cr.aliyuncs.com/pai/torcheasyrec:1.1.0-pytorch2.10.0-gpu-py311-cu129-ubuntu22.04

SSH public key

Yes

Enter the SSH public key of your local client, which is used to log on to the sub-container over SSH later.

If you haven't generated an SSH key pair, run ssh-keygen -t rsa -b 4096 in a local terminal. By default, the public key is saved in ~/.ssh/id_rsa.pub

Main container mount

No

On instances that have the persistent system disk enabled, sub-containers can mount any path in the main container. On instances that don't have the persistent system disk enabled, sub-containers can mount only the storage paths and datasets that are mounted on the main container.

Dataset mount

No

Only datasets that are already mounted on the main container, or datasets in their subdirectories, can be mounted.

Environment variables

No

Set custom environment variables for the sub-container in key-value pairs.

For example: ENV=prod

Startup command

No

Specify the command to run when the container starts.

For example: python app.py

Entrypoint

No

Specify the entrypoint of the container.

For example: /bin/bash

Resource information

Parameter

Required

Description

Example

GPU device mount

No

If the DSW instance has GPU resources, you can select the GPU devices to mount when you create the sub-container. All GPU cards of the instance (including device numbers) are listed, and you can select multiple cards.

After you select the GPU devices, they are mounted to the sub-container for use.

CPU limit

No

Set the maximum CPU usage of the sub-container. If you leave this field empty, no limit is enforced, and the sub-container may consume other idle resources on the instance.

For example: 8 cores

Memory limit

No

Set the maximum memory usage of the sub-container. If you leave this field empty, no limit is enforced, and the sub-container may consume other idle resources on the instance.

For example: 48 GiB

After you complete the configuration, click Confirm to create the sub-container. On the sub-container management page, click Child Container Creation Progress to view the creation process.

Manage sub-containers

In the sub-container list, the actions column of each sub-container provides the following operations:

You can manage only the sub-containers that you created.
  • Start: Start a sub-container that is in the Stopped state.

  • Stop: Stop a running sub-container. After the sub-container is stopped, the processes in it are terminated, but the container configuration and mounted storage data are not lost.

  • Restart: Restart a running sub-container. This operation is equivalent to stopping the sub-container and then starting it.

  • Logs: View the runtime logs of the sub-container, which are useful for troubleshooting.

  • SSH connection information: View the SSH connection information of the sub-container, including the connection username and connection command.

  • Delete: Delete the sub-container. Data in the sub-container that is not persisted through mounted storage cannot be recovered after the deletion. Proceed with caution.

View the sub-container list

The sub-container management page displays a list of all sub-containers on the current instance. The list shows the following information:

Note

The list contains only the sub-containers that are created on the sub-container management page. Sub-containers that users created manually by running docker commands are not included.

Field

Description

Container name

The name of the sub-container

Username

The username of the user who created the sub-container

Status

The current status of the sub-container, including Creating (image being pulled), Created, Running, Paused, Restarting, Stopped, Starting, Stopping, and Updating

GPU memory (GiB)

The GPU device number and GPU memory usage

CPU resources

The CPU usage and the number of cores

Memory (GiB)

The memory usage

Container image

The image used by the sub-container

Creation time

The time when the sub-container was created

All users who have DSW read permissions can view the complete sub-container list, but they can start, stop, and delete only the sub-containers they created.

View the container creation task list

Creating a sub-container can take a long time (for example, when a large image must be pulled). The system tracks container creation tasks.

In the upper-right corner of the sub-container management page, click Child Container Creation Progress to view the status and logs of all container creation tasks. You can manually cancel tasks in the Creating state. By default, task records are retained for 3 days and then automatically removed.

Access a sub-container over SSH

After a sub-container is created and is in the Running state, you can log on to it remotely over SSH.

Procedure:

  1. In the sub-container list, find the target sub-container and click SSH connection information in the actions column. The information includes the connection username and the complete connection command.

  2. Copy the connection command generated by the console and run it in a local terminal to log on to the sub-container. The command is in the following format:

ssh <username>@<public-ip-address> -p <public-port> -i <local-private-key-path>

The following table describes the parameters:

Parameter

Description

username

Uniquely bound to a sub-container and displayed in the "Access Method" dialog box

public-ip-address

The public access address of the DSW main container

public-port

The public port mapped to the SSH service of the sub-container

local-private-key-path

The path of the private key file that corresponds to the SSH public key entered when the sub-container was created (for example, ~/.ssh/id_rsa)

After you log on over SSH, you enter the command-line environment of the corresponding sub-container. All sub-containers share the public port of the DSW main container. Access is isolated through the distinct SSH key and dedicated connection username of each sub-container.

Usage notes and limitations

  • Dependency on the main container state: All sub-container management capabilities depend on the running state of the DSW main container. If the main container is stopped or in an abnormal state, the sub-container management page is unavailable, and the sub-containers cannot be accessed.

  • Storage mount scope: Sub-containers can mount only directory paths in the main container. External storage cannot be mounted directly.

  • Sub-container count limit: The number of sub-containers on each instance is subject to the limit configured by the administrator. The maximum configurable limit is 16.

  • Feature scope: Sub-containers don't provide the complete development environment of the DSW main container (such as the built-in JupyterLab, Terminal, and WebIDE applications). Sub-containers are currently accessed over SSH.

  • Data persistence: Data in a sub-container that is not persisted through mounted storage cannot be recovered after the sub-container is deleted. Store important data in mounted directories.

  • Impact of instance deletion: When a DSW instance is deleted, all sub-containers on it are deleted as well. Back up your data in advance.

FAQ

Q: Why can't I see the sub-container management tab on the instance details page?

Check the following:

  1. The Enable Multi-Container Isolation (DinD) feature was enabled when the DSW instance was created.

  2. The DSW main container is in the Running state. When the main container isn't running, the sub-container management tab isn't displayed.

Q: Why can't I mount data directories when I create a sub-container?

The instance administrator may have configured a data directory isolation policy, and no available directories are assigned to your RAM user in the configuration file. Contact the instance administrator to add an entry for you in mount_access.json.

Q: Why does the SSH connection to a sub-container fail?

Check the following in order:

  1. Whether the sub-container is in the Running state

  2. Whether the local private key you use matches the public key you entered when you created the sub-container

  3. Whether SSH is enabled on the DSW instance

  4. Whether your network can access the public address and the SSH public port of the instance

Q: Why does creating a sub-container take a long time?

The sub-container creation time mainly depends on the image pull speed. Pulling a large image for the first time can take a long time. You can view the progress and logs in the container creation task list. When you create a new container from the same image later, the creation is much faster because the image is already cached locally.

Q: Can I manage sub-containers created by other users?

Yes. Whether you can depends on your role and the operation permission settings of the instance.

  • Workspace owners, workspace administrators, and instance owners have full operation permissions on the instance. They can manage sub-containers created by any user and are not affected by the restriction that forbids operating or changing the instance.

  • Users with the algorithm development or algorithm O&M role, and custom roles that have the DSW read-only permission, can by default also manage sub-containers created by other users. After these roles are restricted from operating or changing the instance, they can manage only the sub-containers they created.

  • All users who have DSW read permissions can view the basic information of all sub-containers.