1

I have build a ehtereum private network with docker and it could run normaly. But if I try to persist the chaindata by using volumes, the node will connect mainnet, instead of my private network. Here is my docker-compose and Docker file code with normal start: docker-compose file:

version: '3.7'

services:
  node:
    hostname: geth-node
    env_file:
      - .env
    build:
      dockerfile: Dockerfile
      context: .
    volumes:
      - ./data/keystore:/root/.ethereum/keystore
    command:
      --identity "node0" 
      --datadir /root/.ethereum 
      --keystore /root/.ethereum/keystore 
      --mine 
      --miner.threads=1 
      --miner.etherbase=${ACCOUNT_ADDRESS} 
      --networkid=${NETWORK_ID} 
      --http 
      --http.addr='0.0.0.0' 
      --http.corsdomain "*" 
      --http.api='eth,net,web3,personal,miner,admin' 
      --bootnodes='' 
      --port 30303 
      --nat extip:${IP} 
      --allow-insecure-unlock 
      --nodiscover 
      --authrpc.addr localhost 
      --authrpc.port 8551
    ports:
      - "30303:30303"  
      - "30303:30303/udp"  
      - "8545:8545"  
      - "8551:8551"
    networks:
      priv-eth-net:


networks:
  priv-eth-net:
    driver: bridge
    ipam:
      config:
      - subnet: 172.31.1.0/24

Dockerfile.

FROM ethereum/client-go:release-1.11

ARG ACCOUNT_PASSWORD

COPY genesis.json /tmp
RUN cat /tmp/genesis.json

RUN geth init /tmp/genesis.json  \
  && rm -f ~/.ethereum/geth/nodekey 

ENTRYPOINT ["geth"]

This is genesis.file

{
  "config": {
    "chainId": 123,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "ethash": {}
  },
  "difficulty": "400000",
  "gasLimit": "12000000",
  "alloc": {
      "77696b3b83037ce9a0f90d38b0af8e717d74591f": { "balance": "1000000000000000000" }}
}

and it connects to my private network rightful enter image description here

But if I replace '- ./data/keystore:/root/.ethereum/keystore' to '- ./data:/root/.ethereum'. It will connect the mainnetenter image description here

so how can I run my private network and persist the chaindata?

2
  • Did you create a genesis file or called geth init? If it isn't provided the node connects to mainnet.
    – Ismael
    Commented Aug 30 at 14:31
  • Yes, I have created. This is why I could connect to my private network If I just specify the keystore path as the first terminal screenshot. But if I I replace '- ./data/keystore:/root/.ethereum/keystore' to '- ./data:/root/.ethereum', it will connect mainnet
    – Tianhao Wu
    Commented Sep 2 at 9:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.