Docker Deployment Guide for Ethereum Private Chain (v1.10.16)

ยท

Introduction

This guide provides step-by-step instructions for deploying an Ethereum private chain using Docker. Key components include:


Part 1: Ethereum Private Chain Image Creation

1.1 Download Base Ethereum Image

docker pull ethereum/client-go:v1.10.16

1.2 Dockerfile Configuration

Create a Dockerfile with the following content:

FROM ethereum/client-go:v1.10.16
RUN apk update && apk add bash curl
ADD bin /root/bin
RUN chmod a+x /root/bin/*
ENTRYPOINT /root/bin/start.sh

1.3 Directory Structure Setup

mkdir -p /opt/docker/images/geth-1.10.16/bin

1.4 Startup Script (start.sh)

#!/bin/bash
set -e

# Initialize geth
echo "Init geth"
geth init "/root/files/genesis.json"
sleep 3

# Start geth
echo "Start geth"
geth --gcmode "archive" \
     --networkid=666666 \
     --http \
     --http.api "db,eth,net,web3,personal,admin,miner" \
     --http.addr "0.0.0.0" \
     --http.port "8545" \
     --miner.threads 1 \
     --mine \
     --allow-insecure-unlock &
sleep 10

while true; do
    sleep 1000000000
done

Key Parameters:

1.5 Build Custom Image

docker build . -t privte-eth:v1.10.16

Verify the image creation:

docker images | grep privte-eth

Part 2: Private Chain Container Setup

2.1 File Preparation

  1. Account Setup:

    • Pre-generate an account address using MetaMask or similar tools
    • Store the private key securely
  2. Directory Structure:

    mkdir -p /opt/docker/eth/data/chain/keystore
    mkdir -p /opt/docker/eth/data/ethash
  3. Genesis Block Configuration (genesis.json):

    {
      "config": {
     "chainId": 666666,
     "homesteadBlock": 0,
     "eip150Block": 0,
     "eip155Block": 0,
     "eip158Block": 0,
     "byzantiumBlock": 0,
     "constantinopleBlock": 0,
     "petersburgBlock": 0,
     "istanbulBlock": 0
      },
      "difficulty": "0x400",
      "gasLimit": "0x800000000000",
      "alloc": {
     "0x6e60F5243e1a3F0Be3F407b5AFE9e5395ee82aa2": {
       "balance": "6660010000000000000000000000"
     }
      }
    }

Pro Tip: ๐Ÿ‘‰ Learn more about genesis block configuration


FAQ Section

Q1: Why specify networkid in both command and genesis file?

The networkid parameter ensures network isolation. Matching values prevent accidental connections to mainnet/testnet.

Q2: What's the purpose of the DAG directory?

The ethash directory stores precomputed mining data, preventing regeneration during container restarts.

Q3: How do I access the JSON-RPC interface?

Use HTTP requests to http://[HOST_IP]:8545 with the configured APIs (eth, web3, etc.).

๐Ÿ‘‰ Explore advanced Ethereum deployment strategies


Best Practices

  1. Security: Always use strong passwords for account keystores
  2. Performance: Adjust difficulty in genesis.json for faster block generation
  3. Monitoring: Implement logging via --verbosity flag

Final Tip: For production environments, consider using orchestration tools like Kubernetes to manage multiple nodes.