You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无互联网局域网内多树莓派Docker应用部署工作流问询

Offline LAN Docker Deployment Workflow for Raspberry Pi Nodes

Absolutely, you can build Docker images on your PC_A and deploy them to offline Raspberry Pi devices in your local network—this is totally feasible with the right setup. Let’s walk through your questions and the step-by-step workflow, including how to leverage docker-machine and Docker Swarm as you’ve already researched.

1. Can I build images on PC_A and deploy to offline LAN Raspberry Pis?

Yes, definitely! The key caveat here is architecture compatibility: most PCs run x86_64, while Raspberry Pis use ARM (typically armv7 or arm64). You’ll need to build multi-architecture images (or ARM-specific images) on PC_A so they run correctly on the Pi hardware.

You don’t need internet access for the deployment phase once all prerequisites are in place—just a working LAN connection between PC_A and your Pis.

2. Required Configurations & Step-by-Step Workflow

Let’s break this down into actionable steps, covering both individual Pi deployment and Swarm cluster setup:

Prerequisites (Do These First, with Internet Access)

  • Prepare Raspberry Pis:
    • Install Docker on each Pi while you have internet: Download the appropriate .deb packages for your Pi’s OS (e.g., Raspberry Pi OS) and transfer them via USB/SD card. Install with:
      sudo dpkg -i docker-ce_*.deb docker-ce-cli_*.deb containerd.io_*.deb
      sudo systemctl start docker
      sudo systemctl enable docker
      sudo usermod -aG docker pi  # Let the pi user run Docker without sudo
      
    • Enable SSH on each Pi (via raspi-config or sudo systemctl enable ssh).
    • Ensure all Pis and PC_A are on the same LAN, and you can ping each Pi from PC_A.
  • Prepare PC_A:
    • Install Docker (with buildx support for multi-architecture builds).
    • Set up SSH key-based authentication to your Pis (so you don’t enter passwords repeatedly):
      ssh-keygen  # Accept defaults
      ssh-copy-id pi@<PI_IP_ADDRESS>  # Repeat for each Pi
      

Option 1: Deploy to Individual Pis with docker-machine

docker-machine lets you manage Docker daemons on remote Pis directly from PC_A.

  1. Add Pis as Docker Machines:
    For each Pi, run:
    docker-machine create \
      --driver generic \
      --generic-ip-address=<PI_IP> \
      --generic-ssh-user=pi \
      pi-node-<NUMBER>
    
  2. Build ARM-Compatible Images on PC_A:
    Use Docker Buildx to build an ARM-specific image (replace linux/arm/v7 with linux/arm64 if using Pi 4+/64-bit OS):
    # Initialize Buildx (if not already done)
    docker buildx create --name multiarch --use
    docker buildx inspect --bootstrap
    
    # Build and load the ARM image to your local Docker
    docker buildx build --platform linux/arm/v7 -t my-pi-app:latest --load .
    
  3. Transfer & Load Image to Pis:
    You can either:
    • Export the image as a tar file and copy it to each Pi:
      docker save -o my-pi-app.tar my-pi-app:latest
      docker-machine scp my-pi-app.tar pi-node-<NUMBER>:/home/pi/
      docker $(docker-machine config pi-node-<NUMBER>) load -i /home/pi/my-pi-app.tar
      
    • Or directly push the image to a local registry (if you set one up on a Pi, but this requires LAN connectivity only).
  4. Run Containers on Pis:
    From PC_A, execute commands on the remote Pi’s Docker daemon:
    docker $(docker-machine config pi-node-<NUMBER>) run -d --name my-app my-pi-app:latest
    

Option 2: Deploy to a Docker Swarm Cluster (For 5 Pis)

Swarm makes managing a cluster of Pis easier—you can deploy services across all nodes from PC_A.

  1. Initialize Swarm on One Pi (Manager Node):
    SSH into one Pi and run:
    docker swarm init --advertise-addr <MANAGER_PI_IP>
    
    Copy the docker swarm join command that’s output (you’ll need this for worker nodes).
  2. Join Worker Pis to the Swarm:
    On each remaining Pi, run the join command from step 1 (e.g.):
    docker swarm join --token <SWARM_WORKER_TOKEN> <MANAGER_PI_IP>:2377
    
  3. Connect PC_A to the Swarm Manager:
    From PC_A, use SSH to connect to the Swarm manager’s Docker daemon:
    export DOCKER_HOST=ssh://pi@<MANAGER_PI_IP>
    
    Now any Docker command you run on PC_A will target the Swarm cluster.
  4. Deploy Your Service:
    Create a docker-compose.yml file on PC_A (example):
    version: '3.8'
    services:
      my-pi-service:
        image: my-pi-app:latest
        deploy:
          replicas: 5  # One instance per Pi
          placement:
            max_replicas_per_node: 1
        ports:
          - "8080:8080"
    
    Deploy the stack to the Swarm:
    docker stack deploy -c docker-compose.yml my-pi-stack
    
    Note: Ensure the my-pi-app:latest image is loaded on every Pi before deployment (use the tar transfer method from Option 1).

Key Tips for Offline Success

  • Batch Operations: Write a simple bash script to transfer and load images to all Pis at once (loop through IP addresses with scp and docker-machine commands).
  • Local Registry (Optional): If you have a Pi with extra storage, set up a local Docker registry (docker run -d -p 5000:5000 --restart always registry:2). Then push your ARM image to localhost:5000/my-pi-app from PC_A, and pull it on Pis using the registry’s LAN IP—this avoids transferring tar files individually.

内容的提问来源于stack exchange,提问作者Julius s

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:18:14