✅ 1. Dockerfile with APT and NPM configured to use Aliyun mirrors
This is a complete Dockerfile example with:
- APT sources replaced with Aliyun mirrors
- NPM registry set to Aliyun’s npmmirror
- Optional installation of 7z
- Clean-up of APT cache
FROM node:20-bullseye-slim
ENV DEBIAN_FRONTEND=noninteractive \
    TZ=Asia/Shanghai
# Replace APT sources with Aliyun mirrors and install dependencies
RUN sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list && \
    sed -i 's|http://security.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list && \
    apt-get update && \
    apt-get install -y p7zip curl ca-certificates && \
    apt-get clean && rm -rf /var/lib/apt/lists/*
# Configure npm to use Aliyun registry
RUN npm config set registry https://registry.npmmirror.com
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 12345
CMD ["node", "index.js"]
✅ 2. docker-compose + custom script for mirror configuration
You can also use docker-compose to start the container and run a script inside it to configure mirrors at runtime.
🧱 Recommended directory structure:
.
├── docker-compose.yml
├── Dockerfile
└── scripts/
    └── set_aliyun_sources.sh
📄 docker-compose.yml example:
version: '3.9'
services:
  mihomo-subserver:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: mihomo-subserver
    network_mode: host
    volumes:
      - /mnt/sdb/node_sites/data:/data
      - /tmp/:/tmp
    restart: always
    entrypoint: ["/bin/bash", "-c", "./scripts/set_aliyun_sources.sh && node index.js"]
📜 scripts/set_aliyun_sources.sh script (same logic as before):
#!/bin/bash
set -e
echo "Configuring APT and NPM to use Aliyun mirrors..."
if grep -qi "debian" /etc/os-release; then
    sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list
    sed -i 's|http://security.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list
elif grep -qi "ubuntu" /etc/os-release; then
    sed -i 's|http://.*.ubuntu.com|http://mirrors.aliyun.com|g' /etc/apt/sources.list
fi
apt-get update -y
npm config set registry https://registry.npmmirror.com
echo "✅ Aliyun mirror configuration complete"
Make sure the script is executable:
chmod +x scripts/set_aliyun_sources.sh