How I run cardano node in docker

I personally see a lot of question here and in telegram group regarding how to run cardano-node in docker.

I personally use IOHK prebuild docker images, what works quite well and it is quite easy to use. I do use docker-compose for that.

To set-up relay is super straightforward:

apt-get update && apt-get upgrade -y && apt-get install docker-compose -y
mkdir -p /docker && cd /docker
git clone https://github.com/os11k/relay.git
mkdir -p /docker/relay/node-config
cd ./relay/node-config
wget https://book.world.dev.cardano.org/environments/preprod/alonzo-genesis.json
wget https://book.world.dev.cardano.org/environments/preprod/byron-genesis.json
wget https://book.world.dev.cardano.org/environments/preprod/shelley-genesis.json
wget https://book.world.dev.cardano.org/environments/preprod/config.json
wget https://book.world.dev.cardano.org/environments/preprod/topology.json
cd ..
docker-compose up -d --build

That will get you relay running with default configs from Cardano and you can check the tip by:

docker exec -ti preprod-relay /usr/local/bin/cardano-cli query tip --testnet-magic 1

Let me explain a bit what is where:
image

node-config is our relay configuration what we downloaded from Cardano World Repository, if you change those files to mainnet files or preview and etc. It will just work, so super straightforward in easy to reuse, for example you run pre-prod pool and everything works there then you use same code, just different config files and you will get 100% same environment.

If you check Dockerfile, you will see there command what we run to lunch our node, it can be adjusted too, setting some flags(like in my example or adding certificate and keys to make it producer). You can change docker image what to use there too, currently in this example it is 1.35.3

node-db are DB files, so if we need to run several nodes we can sync one, shut it down and then distribute that directory between other nodes and all of them are sync, quite a nit trick, if you will ask me.

I have following code in Docker file for producer:

FROM inputoutput/cardano-node:1.35.3
ENV CARDANO_NODE_SOCKET_PATH=/ipc/node.socket
ENTRYPOINT ["/usr/local/bin/cardano-node", "run", "+RTS", "-N", "-A16m", "-qg", "-qb", "-RTS", "--topology", "/config/topology.json", "--database-path", "/data/db", "-socket-path", "/ipc/node.socket", "--host-addr", "0.0.0.0", "--port", "3001", "--config", "/config/config.json", "--shelley-kes-key", "/config/kes.skey", "--shelley-vrf-key", "/config/vrf.skey", "--shelley-operational-certificate", "/config/node.cert" ]

So here we need to have additionally /config/kes.skey, /config/vrf.skey & /config/node.cert those files should be in ./node-config directory what is mounted as /config directory inside docker.

Off cause you should not forget o update your topology.json accordingly.

I don’t use topology-updater anymore, but when I did, I ran it from the host machine, not from docker, what worked quite well for me.

To shutdown our node, just do following:

cd ./relay
docker-compose down

To start it up again:

cd ./relay
docker-compose up -d --build

To check logs:

docker logs preprod-relay

Our docker name is set to preprod-relay inside docker-compose.yml, you can change it accordingly.

Probably you will like to edit or update config of node inside ./node-config/config.json and change for example prometheus port and or ip and etc, just don’t forget to restart your docker after it.

I think that it is most of it and definitely not something super difficult, let me know if I missed something, or maybe you have some ideas how to improve this code.

Cheers!

1 Like

You are doing everything as root, not as an unprivileged user?

Good point, this manual is intended for preprod mainly and I used my preprod environment as source for this manual and I’m not so tight with it, honestly. Nevertheless you are correct using root should be limited.