# 🧱 使用 Docker Compose 部署以太坊 Sepolia 测试网全节点（Geth + Prysm）

By [pangdong](https://paragraph.com/@pangdong) · 2025-05-17

---

![区块链实验室(33) - 用Geth+Prysm创建一个Ethereum私链](https://storage.googleapis.com/papyrus_images/a20ffe477588e0a9857bd01fc61c97c108a67d6eb3dd7a0699b4b6b261f01e97.jpg)

区块链实验室(33) - 用Geth+Prysm创建一个Ethereum私链

以下是关于在 Ubuntu 系统上使用 Docker Compose 部署以太坊 Sepolia 测试网全节点的中文教程，包含执行客户端 Geth 和共识客户端 Prysm 的配置。

* * *

📋 系统与硬件要求
----------

*   **操作系统**：Ubuntu 20.04 或更高版本
    
*   **CPU**：4 核或以上
    
*   **内存**：16 GB 或以上
    
*   **存储**：SSD，至少 1 TB 可用空间
    
*   **网络**：下载速度 ≥ 25 Mbps([bcskill.com](https://www.bcskill.com/index.php/category/Ethereum-%E6%96%B0%E6%89%8B%E6%95%99%E7%A8%8B/3/?utm_source=chatgpt.com), [CSDN博客](https://blog.csdn.net/yvge669/article/details/140736590?utm_source=chatgpt.com))
    

* * *

🛠️ 第一步：安装系统依赖与 Docker
----------------------

### 更新系统并安装必要工具

    sudo apt-get update && sudo apt-get upgrade -y
    sudo apt install -y curl git wget build-essential jq lz4 tmux htop unzip
    

### 安装 Docker 与 Docker Compose

    # 移除旧版本
    for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
    
    # 安装依赖
    sudo apt-get update
    sudo apt-get install -y ca-certificates curl gnupg
    
    # 添加 Docker 官方 GPG 密钥
    sudo install -m 0755 -d /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    
    # 设置 Docker 仓库
    echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
      $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
      sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
    # 安装 Docker Engine
    sudo apt-get update
    sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    
    # 启动并设置 Docker 开机自启
    sudo systemctl enable docker
    sudo systemctl start docker
    
    # 测试 Docker 安装
    sudo docker run hello-world
    

* * *

📁 第二步：创建项目目录
-------------

    mkdir -p ~/ethereum/{execution,consensus}
    cd ~/ethereum
    

* * *

🔐 第三步：生成 JWT 密钥
----------------

    openssl rand -hex 32 > jwt.hex
    cat jwt.hex
    

* * *

📝 第四步：编写 Docker Compose 配置文件
-----------------------------

    nano docker-compose.yml
    

将以下内容粘贴到文件中：

    version: '3.8'
    
    services:
      geth:
        image: ethereum/client-go:stable
        container_name: geth
        network_mode: host
        restart: unless-stopped
        volumes:
          - ./execution:/data
          - ./jwt.hex:/data/jwt.hex
        command:
          - --sepolia
          - --http
          - --http.api=eth,net,web3
          - --http.addr=0.0.0.0
          - --authrpc.addr=0.0.0.0
          - --authrpc.vhosts=*
          - --authrpc.jwtsecret=/data/jwt.hex
          - --authrpc.port=8551
          - --syncmode=snap
          - --datadir=/data
        logging:
          driver: "json-file"
          options:
            max-size: "10m"
            max-file: "3"
    
      prysm:
        image: gcr.io/prysmaticlabs/prysm/beacon-chain
        container_name: prysm
        network_mode: host
        restart: unless-stopped
        volumes:
          - ./consensus:/data
          - ./jwt.hex:/data/jwt.hex
        depends_on:
          - geth
        ports:
          - 4000:4000
          - 3500:3500
        command:
          - --sepolia
          - --accept-terms-of-use
          - --datadir=/data
          - --disable-monitoring
          - --rpc-host=0.0.0.0
          - --execution-endpoint=http://127.0.0.1:8551
          - --jwt-secret=/data/jwt.hex
          - --rpc-port=4000
          - --grpc-gateway-corsdomain=*
          - --grpc-gateway-host=0.0.0.0
          - --grpc-gateway-port=3500
          - --min-sync-peers=3
          - --checkpoint-sync-url=https://checkpoint-sync.sepolia.ethpandaops.io
          - --genesis-beacon-api-url=https://checkpoint-sync.sepolia.ethpandaops.io
        logging:
          driver: "json-file"
          options:
            max-size: "10m"
            max-file: "3"
    

* * *

🚀 第五步：启动节点
-----------

    docker compose up -d
    

查看日志：

    docker compose logs -f
    

* * *

🔍 第六步：检查节点同步状态
---------------

### 检查 Geth 同步状态

    curl -X POST -H "Content-Type: application/json" \
    --data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' \
    http://localhost:8545
    

*   返回 `false` 表示已同步完成。
    
*   返回包含 `startingBlock`、`currentBlock` 和 `highestBlock` 的对象，表示仍在同步中。
    

### 检查 Prysm 同步状态

    curl http://localhost:3500/eth/v1/node/syncing
    

*   `is_syncing: false` 且 `sync_distance: 0` 表示已同步完成。
    
*   `is_syncing: true` 表示仍在同步中。
    

* * *

🔐 第七步：配置防火墙（可选）
----------------

    # 允许 SSH 连接
    sudo ufw allow 22
    sudo ufw allow ssh
    
    # 允许 Geth P2P 端口
    sudo ufw allow 30303/tcp
    sudo ufw allow 30303/udp
    
    # 允许本地访问 RPC 端口
    sudo ufw allow from 127.0.0.1 to any port 8545 proto tcp
    sudo ufw allow from 127.0.0.1 to any port 3500 proto tcp
    
    # 启用防火墙
    sudo ufw enable
    

* * *

🌐 第八步：访问 RPC 接口
----------------

*   **Geth 执行层 RPC**：
    
    *   本地访问：`http://localhost:8545`
        
    *   外部访问：`http://<服务器公网IP>:8545`
        
*   **Prysm 共识层 RPC**：
    
    *   本地访问：`http://localhost:3500`
        
    *   外部访问：`http://<服务器公网IP>:3500`([博客园](https://www.cnblogs.com/Soy-technology/p/18355486?utm_source=chatgpt.com))
        

* * *

📊 第九步：监控系统资源
-------------

*   实时查看系统资源使用情况：
    

*   查看磁盘使用情况：
    

      df -h
    

*   查看 Geth 数据目录大小：
    

      docker exec -it geth du -sh /data
    

*   查看 Prysm 数据目录大小：
    

      docker exec -it prysm du -sh /data
    

* * *

📚 参考资料
-------

*   Prysm 官方文档：[https://docs.prylabs.network/docs/getting-started/](https://docs.prylabs.network/docs/getting-started/)
    
*   Geth 官方文档：[https://geth.ethereum.org/docs/](https://geth.ethereum.org/docs/)
    
*   Sepolia 测试网信息：[https://sepolia.dev/](https://sepolia.dev/)([rocdk890.github.io](https://rocdk890.github.io/2022/12/15/ETH-2.0%E4%B8%BB%E7%BD%91%E8%8A%82%E7%82%B9%E6%90%AD%E5%BB%BA%E6%95%99%E7%A8%8B%28geth%2Bprysum%29/?utm_source=chatgpt.com), [博客园](https://www.cnblogs.com/Soy-technology/p/18355486?utm_source=chatgpt.com))
    

* * *

通过以上步骤，您可以在 Ubuntu 系统上使用 Docker Compose 成功部署一个以太坊 Sepolia 测试网全节点，包含执行客户端 Geth 和共识客户端 Prysm。([bcskill.com](https://www.bcskill.com/index.php/archives/1723.html?utm_source=chatgpt.com))

如果要运行主网则把docker-compose.yml修改为下面

     version: '3.8'
    
    services:
      geth:
        image: ethereum/client-go:stable
        container_name: geth
        network_mode: host
        restart: unless-stopped
        volumes:
          - ./execution:/data
          - ./jwt.hex:/data/jwt.hex
        command:
          - --mainnet
          - --http
          - --http.api=eth,net,web3
          - --http.addr=0.0.0.0
          - --authrpc.addr=0.0.0.0
          - --authrpc.vhosts=*
          - --authrpc.jwtsecret=/data/jwt.hex
          - --authrpc.port=8551
          - --syncmode=snap
          - --datadir=/data
        logging:
          driver: "json-file"
          options:
            max-size: "10m"
            max-file: "3"
    
      prysm:
        image: gcr.io/prysmaticlabs/prysm/beacon-chain
        container_name: prysm
        network_mode: host
        restart: unless-stopped
        volumes:
          - ./consensus:/data
          - ./jwt.hex:/data/jwt.hex
        depends_on:
          - geth
        ports:
          - 4000:4000
          - 3500:3500
        command:
          - --mainnet
          - --accept-terms-of-use
          - --datadir=/data
          - --disable-monitoring
          - --rpc-host=0.0.0.0
          - --execution-endpoint=http://127.0.0.1:8551
          - --jwt-secret=/data/jwt.hex
          - --rpc-port=4000
          - --grpc-gateway-corsdomain=*
          - --grpc-gateway-host=0.0.0.0
          - --grpc-gateway-port=3500
          - --min-sync-peers=3
          - --checkpoint-sync-url=https://beaconstate.ethstaker.cc
          - --genesis-beacon-api-url=https://beaconstate.ethstaker.cc
        logging:
          driver: "json-file"
          options:
            max-size: "10m"
            max-file: "3"
    

### 📌 重要说明

数据的当前路径为 `./execution` 和 `./consensus`，请确保有充足磁盘空间（建议至少 **2TB SSD**）

JWT 密钥文件

请提前在当前目录生成：`openssl rand -hex 32 > jwt.hex`

---

*Originally published on [pangdong](https://paragraph.com/@pangdong/docker-compose-sepolia-geth-prysm)*
