Skip to main content

Run 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=goerli --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
tip

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=goerli --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=goerli --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=/var/lib/besu/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",
"--engine-jwt-secret=/var/lib/besu/data/token.txt",
"--engine-host-allowlist=*",
"--engine-rpc-enabled=true",
]
volumes:
- ./besu:/var/lib/besu/data
ports:
# Map the p2p port(30303), RPC HTTP port(8545), and engine port (8551)
- "8545:8545"
- "8551:8551"
- "30303:30303/tcp"
- "30303:30303/udp"

teku_node:
environment:
- "JAVA_OPTS=-Xmx4g"
image: consensys/teku:latest
command:
[
"--network=goerli",
"--data-base-path=/var/lib/teku/data",
"--validators-proposer-default-fee-recipient=YOUR_WALLET",
"--ee-endpoint=http://besu_node:8551",
"--ee-jwt-secret-file=/var/lib/teku/data/token.txt",
"--validator-keys=/var/lib/teku/data/validator/keys:/var/lib/teku/data/validator/passwords",
"--p2p-port=9000",
"--rest-api-enabled=true",
"--rest-api-docs-enabled=true",
]
depends_on:
- besu_node
volumes:
- ./teku:/var/lib/teku/data
ports:
# Map the p2p port(9000) and REST API port(5051)
- "9000:9000/tcp"
- "9000:9000/udp"
- "5051:5051"