

Các công nghệ container được dùng rộng rãi để triển khai phần mềm và tái lập trong tính toán khoa học. Tuy nhiên, Docker truyền thống có những hạn chế trong môi trường High-Performance Computing (HPC). Bài này xem xét vì sao Docker không phù hợp với hệ thống HPC dùng chung, và giới thiệu những lựa chọn thay thế thường được dùng ở đó: Docker rootless, Singularity và Apptainer.
Mô hình bảo mật của Docker khiến nó gây trở ngại cho hệ thống HPC dùng chung.
Docker cần quyền root để chạy container. Daemon của Docker hoạt động ở cấp hệ thống và cần quyền cao hơn để:
Trên hệ thống HPC có nhiều người dùng chia sẻ tài nguyên, việc cấp quyền Docker cho tất cả người dùng sẽ tạo ra vấn đề bảo mật. Một người dùng có quyền Docker có thể:
Ví dụ dưới đây minh hoạ cách một người dùng thường có thể nâng quyền lên root bằng Docker:
# A normal user with docker group membershipwhoami# Output: regularuser
# User runs a container and mounts the entire root filesystemdocker run -v /:/host -it ubuntu:latest bash
# Inside the container, the user can access ALL system files as rootroot@container# cat /host/etc/shadow# This reveals root password hashes that should be inaccessible!
root@container# cat /host/root/.ssh/id_rsa# Can steal other users' SSH keys
root@container# whoami# Output: root (inside the container)
# User can write files as rootroot@container# echo "malicious content" > /host/etc/cron.d/backdoorĐiều gì đã xảy ra ở đây?
/etc/shadow, cron job).# Another example: avoiding resource limits# User runs a container with no resource restrictionsdocker run -it --memory=unlimited --cpus=unlimited ubuntu:latest
# Inside the container, a fork bomb can exhaust the node:(){ :|:& };:
# This can crash the entire HPC node, affecting all other usersVì sao đây là vấn đề:
# Standard Docker setup (unsafe on shared systems)sudo usermod -aG docker regularuser
# Now regularuser can:docker run -v /:/host ... # Access ANY file on the systemdocker run --privileged ... # Run as rootdocker pull malicious:latest # Download backdoored containersĐó là lý do các quản trị viên thường không cấp quyền truy cập nhóm docker trên hệ thống HPC dùng chung.
# Typical Docker setup requires sudosudo docker run -it ubuntu:latest bash
# Even with docker group membership, this is a privilege escalation vectordocker run -it ubuntu:latest bashCác cụm HPC là môi trường được quản lý với:
Kiến trúc daemon đơn khối của Docker xung đột với những yêu cầu này. Quản trị viên hạn chế Docker để ngăn vi phạm bảo mật và xung đột tài nguyên.
Docker rootless cho phép Docker chạy mà không cần quyền root, giải quyết một lớp của vấn đề nâng quyền. Nó dùng user namespace để cách ly daemon và container.
Cài đặt:
# Install rootless Dockercurl https://get.docker.com/rootless | sh
# Verify installationdockerd-rootless-setuptool.sh install
# Start the daemonsystemctl --user start dockerDùng rootless Docker:
# No sudo needed!docker run -it ubuntu:latest bash
# Check the userdocker run whoami# Output: root (but it's a mapped non-root user)Docker rootless là một bước tiến, nhưng chưa giải quyết được sự không khớp giữa thiết kế của Docker và yêu cầu của HPC.
Singularity được xây dựng cho môi trường HPC. Nó giải quyết các vấn đề bảo mật và lập lịch mà Docker gặp trên cụm. Năm 2021, nó được mở mã nguồn với tên Apptainer bởi Linux Foundation.
Thiết kế hướng người dùng:
# Run as normal user, no daemon requiredsingularity run mycontainer.sif
# Direct execution without privilege escalationsingularity exec mycontainer.sif python script.pyContainer là một file duy nhất:
# Portable and easy to managels -lh mycontainer.sif# Output: -rw-r--r-- 1 user group 2.5G Feb 11 10:00 mycontainer.sif
# Copy between systemscp mycontainer.sif /cluster/home/user/Giữ nguyên danh tính và quyền của người dùng:
# Inside container, you're still yourselfsingularity exec mycontainer.sif id# Output: uid=1001(user) gid=1002(group)...
# Access your files as expectedsingularity exec mycontainer.sif ls -la ~Vì Singularity/Apptainer được dùng phổ biến trên nhiều hệ thống HPC và workflow bioinformatics, một cách là cài chúng toàn cục bằng Pixi, thường đơn giản và đáng tin cậy hơn các trình quản lý gói truyền thống.
Bước 1: Cài Pixi (nếu chưa có):
# One-time setupcurl -fsSL https://pixi.sh/install.sh | bash
# Add pixi to your PATH to use in current shell, or open new shell to reloadexport PATH="$HOME/.pixi/bin:$PATH"
# Verify pixi installationpixi --versionBước 2: Cài Apptainer toàn cục:
# Simple one-liner - that's it!pixi global install apptainer
# Verify installationapptainer --versionBước 3 (tuỳ chọn): cài các công cụ bioinformatics phổ biến khác toàn cục:
# Install multiple tools at oncepixi global install apptainer -c conda-forge --expose apptainer
# All tools are now available system-wideapptainer --versionLợi ích của cách này:
pixi global install apptainerpixi global upgrade apptainerKiểm tra cài đặt:
# Check versionapptainer --version
# Run a test container from Docker Hubapptainer run docker://ubuntu:22.04 echo "Apptainer works"
# List available sub-commandsapptainer --helpSau khi cài toàn cục qua Pixi, Apptainer sẵn có cho các dự án và người dùng mà không cần kích hoạt môi trường cho mỗi phiên.
Bạn có thể build từ Docker image hoặc viết definition file gốc.
Cách 1: chuyển đổi một Docker image
# Build directly from Docker Hubapptainer build ubuntu.sif docker://ubuntu:22.04
# Build from existing Docker imageapptainer build myapp.sif docker://myregistry.com/myapp:latestCách 2: viết definition file
Tạo myapp.def:
Bootstrap: dockerFrom: ubuntu:22.04
%post apt-get update apt-get install -y python3 pip pip install numpy scipy
%environment export PATH=/usr/local/bin:$PATH
%runscript exec python3 "$@"
%help This container runs Python analysis scriptsBuild nó:
# Note: first build may require sudo, but running requires no special privilegesapptainer build myapp.sif myapp.def
# Run without any special privilegesapptainer run myapp.sif script.pyVới Slurm:
#!/bin/bash#SBATCH --job-name=analysis#SBATCH --ntasks=4#SBATCH --mem=16GB#SBATCH --time=01:00:00
# Run container through schedulerapptainer run myapp.sif python /data/analysis.pyVới PBS:
#!/bin/bash#PBS -N analysis#PBS -l select=1:ncpus=4:mem=16gb#PBS -l walltime=01:00:00
cd $PBS_O_WORKDIRapptainer run myapp.sif python /data/analysis.pySingularity không can thiệp vào việc phân bổ tài nguyên của scheduler; nó dùng các system call tiêu chuẩn.
| Feature | Singularity/Apptainer | Docker | Docker Rootless |
|---|---|---|---|
| No daemon required | Yes | No | No |
| Single file format | Yes | No | No |
| User identity preserved | Yes | No | Partial |
| HPC scheduler integration | Yes | No | No |
| Permission isolation | Yes | Limited | Limited |
| Resource control | Via cgroups | Native | Limited |
| Learning curve | Moderate | Low | Low |
# Requires privileged setupsudo docker run -v /data:/data myapp:latest \ bwa mem reference.fa reads.fastq > output.sam# No sudo, but still not HPC-optimizeddocker run -v /data:/data myapp:latest \ bwa mem reference.fa reads.fastq > output.sam# Simple, no special privileges, works with Slurmsingularity exec myapp.sif \ bwa mem reference.fa reads.fastq > output.sam
# Or in a Slurm scriptsbatch -N 1 --ntasks=8 --mem=32G myjob.sh# (inside myjob.sh runs singularity as normal)# List your imagesdocker images# Convert existing Docker imagesapptainer build myapp.sif docker://myregistry/myapp:latest
# Or build from Docker Compose# First, build your Docker imagedocker build -t myapp:latest .
# Then convertapptainer build myapp.sif docker-daemon://myapp:latest# Run and verifyapptainer run myapp.sif commandapptainer exec myapp.sif python script.py# Copy to clusterscp myapp.sif user@hpc-cluster:/home/user/
# Use in job scriptssbatch my_job.sh| Scenario | Recommendation |
|---|---|
| Local development | Docker or Docker Desktop |
| Single-user HPC access | Singularity/Apptainer |
| Multi-tenant HPC cluster | Singularity/Apptainer |
| Rootless requirement | Docker rootless or Singularity/Apptainer |
| Kubernetes clusters | Docker or similar (not HPC-focused) |
| Maximum compatibility | Singularity/Apptainer |
Docker phù hợp với phát triển và hạ tầng cloud, nhưng môi trường HPC cần một cách tiếp cận khác. Docker rootless cải thiện mô hình bảo mật của Docker nhưng chưa giải quyết được việc tích hợp HPC.
Singularity/Apptainer là lựa chọn phổ biến cho HPC vì nó:
Trên hệ thống HPC, Singularity/Apptainer là lựa chọn tự nhiên hơn. Với phát triển cục bộ, Docker vẫn thuận tiện; có thể chuyển image sang Singularity khi triển khai lên cụm.





