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
But if I replace '- ./data/keystore:/root/.ethereum/keystore' to '- ./data:/root/.ethereum'. It will connect the mainnet
so how can I run my private network and persist the chaindata?
geth init
? If it isn't provided the node connects to mainnet.