Updated on February 16, 2022
Running Teku from a Docker image
Use the Teku Docker image to run a node without installing Teku.
Prerequisites:
Run Teku Docker image
Display the Teku command line help using the Docker image
docker run consensys/teku:latest --help
You can specify Teku environment variables with the docker image instead of the command line options.
Example using Environment variables and CLI options
docker run -d -p 9000:9000/tcp -p 9000:9000/udp -p 5051:5051 -e TEKU_REST_API_ENABLED=true -e TEKU_P2P_PORT=9000 --mount type=bind,source=/Users/user1/teku/,target=/var/lib/teku consensys/teku:latest --network=prater --eth1-endpoint=http://102.10.10.1:8545 --validator-keys=/var/lib/teku/validator/keys:/var/lib/teku/validator/passwords --data-path=/var/lib/teku --log-destination=CONSOLE
Tips
- If running Docker in the background, set
--log-destination
toconsole
to send all logs to the console and appear in Docker’s log output. - Set
--data-path
to a mount point to ensure Teku data is not lost in the Docker filesystem. - Set the Docker user to the UID of the normal user to ensure read/write access to the required files.
Allow multiple users to run the Docker image
If using a local volume to mount data, ensure the permissions on the directory allow other users and groups to read/write.
Use the Docker --user
option to run
the container for the specified user. Use the UID because the username may not exist inside the
docker container.
Example
docker run -p 9000:9000/tcp -p 9000:9000/udp --user 1001:1001 --mount type=bind,source=/Users/user1/teku/,target=/var/lib/teku consensys/teku:latest --data-base-path=/var/lib/teku --network=prater --eth1-endpoint=http://102.10.10.1:8545 --validator-keys=/var/lib/teku/validator/keys:/var/lib/teku/validator/passwords
Exposing ports
Expose ports for P2P peer discovery, metrics, and REST APIs. Expose the default ports or the ports specified using:
To run Teku exposing local ports for access:
docker run -p <localportP2P>:30303/tcp -p <localportP2P>:30303/udp -p <localportREST>:5051 consensys/teku:latest --network=<NETWORK> --data-base-path=<DATA_DIR> --eth1-endpoint=<URL> --validator-keys=<KEY_DIR>:<PASS_DIR> --rest-api-enabled=true
Example
docker run -p 30303:30303/tcp -p 30303:30303/udp -p 5051:5051 --mount type=bind,source=/Users/user1/teku/,target=/var/lib/teku consensys/teku:latest --network=prater --data-base-path=/var/lib/teku --eth1-endpoint=http://102.10.10.1:8545 --validator-keys=/var/lib/teku/validator/keys:/var/lib/teku/validator/passwords --rest-api-enabled=true
Run Teku using Docker Compose
Prerequisites:
The following docker-compose.yml
file starts a Hyperledger Besu and Teku node.
Note
The example assumes the validators specified in --validator-keys
have already
been registered in the deposit contract.
Run docker-compose up
in the directory containing the docker-compose.yml
file
to start the container.
---
version: '3.4'
services:
besu_node:
image: hyperledger/besu:latest
command: ["--network=goerli",
"--data-path=/opt/besu/data/data",
"--host-allowlist=*",
"--sync-mode=FAST",
"--rpc-http-enabled",
"--rpc-http-cors-origins=*",
"--rpc-http-api=ETH,NET,CLIQUE,DEBUG,MINER,NET,PERM,ADMIN,EEA,TXPOOL,PRIV,WEB3"]
volumes:
- ./besu:/opt/besu/data
ports:
# Map the p2p port(30303) and RPC HTTP port(8545)
- "8545:8545"
- "30303:30303/tcp"
- "30303:30303/udp"
teku_node:
environment:
- "JAVA_OPTS=-Xmx4g"
image: consensys/teku:latest
command: ["--network=prater",
"--data-base-path=/opt/teku/data"
"--eth1-endpoint=http://besu_node:8545",
"--validator-keys=/opt/teku/data/validator/keys:/opt/teku/data/validator/passwords",
"--p2p-port=9000",
"--rest-api-enabled=true",
"--rest-api-docs-enabled=true"]
depends_on:
- besu_node
volumes:
- ./teku:/opt/teku/data
ports:
# Map the p2p port(9000) and REST API port(5051)
- "9000:9000/tcp"
- "9000:9000/udp"
- "5051:5051"
---
version: '3.4'
services:
besu_node:
image: hyperledger/besu:latest
command: ["--data-path=/opt/besu/data/data",
"--host-allowlist=*",
"--rpc-http-enabled",
"--rpc-http-cors-origins=*",
"--rpc-http-api=ETH,NET,CLIQUE,DEBUG,MINER,NET,PERM,ADMIN,EEA,TXPOOL,PRIV,WEB3"]
volumes:
- ./besu:/opt/besu/data
ports:
# Map the p2p port(30303) and RPC HTTP port(8545)
- "8545:8545"
- "30303:30303/tcp"
- "30303:30303/udp"
teku_node:
environment:
- "JAVA_OPTS=-Xmx4g"
image: consensys/teku:latest
command: ["--data-base-path=/opt/teku/data"
"--eth1-endpoint=http://besu_node:8545",
"--validator-keys=/opt/teku/data/validator/keys:/opt/teku/data/validator/passwords",
"--p2p-port=9000",
"--rest-api-enabled=true",
"--rest-api-docs-enabled=true"]
depends_on:
- besu_node
volumes:
- ./teku:/opt/teku/data
ports:
# Map the p2p port(9000) and REST API port(5051)
- "9000:9000/tcp"
- "9000:9000/udp"
- "5051:5051"