Run Docker commands in the main container of a DSW instance to start and manage secondary containers, also known as sub-containers.
To start sub-containers with a graphical user interface, see Manage Sub-containers with DockerBoard.
Limitations
Sub-containers are supported only on DSW instances created with Lingjun resource groups or general-purpose resource groups.
You cannot modify the Docker Daemon configuration (
/etc/docker/daemon.json) of secondary containers in a DSW instance. Therefore, you cannot customize configuration items such asdata-rootandregistry-mirrors.After you restart a DSW instance, the runtime data in secondary containers, including the runtime images that you built, is lost. This applies whether or not the cloud disk feature is enabled. To prevent data loss, regularly save your important environments and data.
When you start a secondary container with Docker, you cannot use parameters that grant elevated privileges or pose security risks. The following table lists common restricted parameters:
Parameter | Description |
| Grants the container nearly all permissions of the host. |
| Shares the IPC namespace of the host. |
| Allows the container to bypass or modify security policies. |
| Adds Linux kernel capabilities to the container and expands its permission scope. |
If you receive the error Error response from daemon: authorization denied by plugin authZ: Permission denied when you run docker run or docker create to create a secondary container, you used a restricted parameter.
Create and configure a DSW instance
When you create a DSW instance, configure the following key parameters. Configure the other parameters as needed:
Resource Type: Select Resource Quota.
Resource Quota: Select the Lingjun resource quota that you created. For more information, see Create a new resource group and purchase Lingjun computing resources.
Enable Multi-Container Isolation (DinD): Turn on this switch.
Click OK to create the instance. For the next steps, see Work with secondary containers.
Work with secondary containers
After your DSW instance is created, run Docker commands in its main container to start and manage secondary containers.
Start a secondary container
Run the following command to start and enter a secondary container:
docker run -it dsw-registry.cn-hangzhou.cr.aliyuncs.com/pai/pytorch:1.8PAI-gpu-py36-cu101-ubuntu18.04 /bin/bashMount devices to a secondary container
GPUs — Use
--gpus=allto mount all GPU devices of the DSW instance.PPUs — Unlike GPUs, PPU devices must be manually mounted to the secondary container by using the
--deviceparameter:
docker run -it --network=host \
--device=/dev/alixpu_ppu0 \
--device=/dev/alixpu \
--device=/dev/alixpu_ctl \
your-ppu-enabled-imageThe runtime image of the secondary container must have the components required by the PPU pre-installed. Otherwise, you cannot use the PPU.
Mount data to a secondary container
Use Docker Bind Mount to access data in a secondary container. Mount the data to the DSW instance by using Dataset Mounting or Storage Path Mounting, and then mount it to the secondary container. Volume Mount and tmpfs Mount are not supported.
For example, if the DSW instance has data mounted at /mnt/data0 and /mnt/data1, use the -v parameter or the --mount parameter to bind mount the data to the secondary container:
# In this example, <path_in_dsw> can be /mnt/data0, /mnt/data1, or their subpaths.
# Other paths cannot be mounted to the secondary container for now.
# Use the -v parameter
docker run -v <path_in_dsw>:<path_in_secondary_container>[:options] {image}
# Use the --mount parameter
docker run --mount type=bind,source=<path_in_dsw>,target=<path_in_secondary_container>[,readonly] {image}Access a secondary container
Use the docker exec command to start a new command process in a running container.
For example, to start a bash shell in interactive mode with standard input open (-i) and a pseudo-terminal allocated (-t), run the following command:
docker exec -it your-container /bin/bashYou cannot use parameters that pose a security risk, such as --privileged, to enter a container for now.
You can also use the docker attach command to attach to the terminal of the main process in a running container. If you started the container with standard input open (-i) and a pseudo-terminal allocated (-t), you can view and interact with the standard input and output (stdin/stdout/stderr) of the container:
docker attach {container_id}The default keyboard shortcut to exit attach mode without stopping the container is Ctrl + p and then Ctrl + q. You are detached from the container terminal, and the container keeps running.
Pull images
Due to network restrictions, you cannot pull images directly from Docker Hub. Pull images from Alibaba Cloud Container Registry (ACR) instead. If pulling an image from Docker Hub fails, see FAQ for error details.
To pull a public image from ACR, run the following command:
docker pull dsw-registry.cn-hangzhou.cr.aliyuncs.com/pai/pytorch:1.8PAI-gpu-py36-cu101-ubuntu18.04To pull an image from a private repository, first run the docker login command to log in:
docker login --username={username} registry.cn-hangzhou.aliyuncs.comBuild an image
In a DSW instance, you can use a Dockerfile to build a runtime image:
docker build -t test-build .When you specify a base image with the FROM instruction, use an image from Alibaba Cloud Container Registry (ACR). For instructions, see Pull images.
After the build is complete, run the following command to view the image:
root@dsw-330808-8445dd65f4-mhnrt:/mnt/workspace/test# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
test-build latest fad7fdb5e81a About a minute ago 15.4GBFAQ
Q: Why are the processes of secondary containers not visible when I run the ps -aux command in a DSW instance?
The main container and secondary containers in a DSW instance do not share a PID namespace. Therefore, the processes of secondary containers are not visible from the main container.
Q: Why does pulling an image from Docker Hub fail?
Due to network restrictions, pulling images directly from Docker Hub fails. You receive the following error:
root@dsw-381955:/mnt/workspace# docker run --network=host -it ubuntu /bin/bash
Unable to find image 'ubuntu:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded.
See 'docker run --help'.Instead, pull images from the Artifact Center of Alibaba Cloud Container Registry (ACR). For instructions, see Pull images. Alternatively, see Cross-domain pull of overseas models or container images.
Q: What do I do if I receive the error "Error response from daemon: authorization denied by plugin authZ: Permission denied"?
You used a Docker command or parameter that is not supported. If you have questions, submit a ticket to contact technical support.
Q: What do I do if I receive the error "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"
Check whether the /var/docker/proxy/docker-proxy.sock file exists in the DSW instance. If the file exists, run the following command:
export DOCKER_HOST=unix:///var/docker/proxy/docker-proxy.sockThen, run the Docker command again.