Cardano-cli cannot connect to node running on docker

Hi all,
I have run cardano node on docker (host centos or ubuntu), do lab, this is my config:

ls /opt/cardano
cardano-node-data  cardano-node-ipc  cardano-wallet  config  docker-compose.yml  note  tokens

cat docker-compose.yml
version: '3.1'
networks:
  net:
    driver: bridge

services:
  cardano-node:
    image: inputoutput/cardano-node
    volumes:
      - ./cardano-node-ipc:/ipc
      - ./cardano-node-data:/data
      - ./note:/note
      - ./config:/config
      - ./tokens:/tokens
      - ./cardano-wallet:/cardano-wallet
    environment:
      - TZ=Asia/Ho_Chi_Minh
      - NETWORK=testnet
      - CARDANO_NODE_SOCKET_PATH=/ipc/node.socket
    networks:
      - net
    ports:
      - "3001:3001"
    expose:
      - 3001
    restart: unless-stopped

cardano node container running ok
Blockchain network data:

du -sh cardano-node-data/db/*
12G     cardano-node-data/db/immutable
683M    cardano-node-data/db/ledger
0       cardano-node-data/db/lock
4.0K    cardano-node-data/db/protocolMagicId
9.9M    cardano-node-data/db/volatile

ls cardano-node-ipc
node.socket

Go to cardano node container shell

docker exec -it cardano_cardano-node_1 bash
set CARDANO_NODE_SOCKET_PATH=/ipc/node.socket

bash-5.1# cardano-cli query tip --testnet-magic 1097911063
{
    "block": 3734385,
    "epoch": 219,
    "era": "Babbage",
    "hash": "b6e65ea5fba8cd0bc854ec9828d01bbcc2129b79fa00a63ce74525ff3fe74a97",
    "slot": 64386435,
    "syncProgress": "98.07"
}

I want to run cardano-cli from my host shell , but it failed:
From my host shell I set $CARDANO_NODE_SOCKET_PATH=/opt/cardano/cardano-node-ipc/node.socket , then I download cardano wallet (build for Linux) from Hydra - Build 11949441 of job Cardano:cardano-wallet:cardano-wallet-linux64 , I tried to connect to cardano node running on docker

/opt/cardano/cardano-wallet/cardano-cli query tip --testnet-magic 1097911063
Command failed: query tip  Error: Error while looking up environment variable: CARDANO_NODE_SOCKET_PATH  Error: "CARDANO_NODE_SOCKET_PATH"

I also try it in cardano node shell but still failed:

bash-5.1# /cardano-wallet/cardano-cli query tip --testnet-magic 1097911063

cardano-cli: DecoderFailure (LocalStateQuery HardForkBlock (': * ByronBlock (': * (ShelleyBlock (ShelleyEra StandardCrypto)) (': * (ShelleyBlock (ShelleyMAEra 'Allegra StandardCrypto)) (': * (ShelleyBlock (ShelleyMAEra 'Mary StandardCrypto)) (': * (ShelleyBlock (AlonzoEra StandardCrypto)) ('[] *)))))) Query (BlockQuery (HardForkBlock (': * ByronBlock (': * (ShelleyBlock (ShelleyEra StandardCrypto)) (': * (ShelleyBlock (ShelleyMAEra 'Allegra StandardCrypto)) (': * (ShelleyBlock (ShelleyMAEra 'Mary StandardCrypto)) (': * (ShelleyBlock (AlonzoEra StandardCrypto)) ('[] *))))))))) ServerAgency TokQuerying BlockQuery (QueryHardFork GetCurrentEra)) (DeserialiseFailure 3 "EraIndex: invalid index 5")

Please give me some advice, thank you very much.

Update: I find out that I’m using cardano docker image v1.35.0 (latest) while
I downloaded cardano wallet (build for Linux) from Hydra - Build 11949441 of job Cardano:cardano-wallet:cardano-wallet-linux64 is 1.33.0 version

so I changed docker-compose.yml
image: inputoutput/cardano-node:1.33.0
Remove all cardano-node-data , restart container, now I can use cardano-cli inside container:

docker exec -it cardano_cardano-node_1 bash
export CARDANO_NODE_SOCKET_PATH=/ipc/node.socket

run cardano-cli of cardano container image

bash-4.4# cardano-cli query tip --testnet-magic 1097911063
{
    "era": "Byron",
    "syncProgress": "7.92",
    "hash": "5683fe8b81ab333daf5d0a5da228b4c272bcc8823a06ba21365671c4fda8e94b",
    "epoch": 17,
    "slot": 382798,
    "block": 381754
}

run cardano-cli which was downloaded from Hydra - Build 11949441 of job Cardano:cardano-wallet:cardano-wallet-linux64 and mouted to container’s volume

bash-4.4# /cardano-wallet/cardano-cli query tip --testnet-magic 1097911063
{
    "era": "Byron",
    "epoch": 17,
    "hash": "b1e5ac20522ab4fda7688216614df13437da795622b4c2640fa06a9644dc91e6",
    "block": 387755,
    "slot": 388799,
    "syncProgress": "8.05"
}

But from same host , I still cannot connect cardano-cli to cardano node running on docker

export CARDANO_NODE_SOCKET_PATH=/opt/cardano/cardano-node-ipc/node.socket
/opt/cardano/cardano-wallet/cardano-cli query tip --testnet-magic 1097911063
Command failed: query tip  Error: Error while looking up environment variable: CARDANO_NODE_SOCKET_PATH  Error: "CARDANO_NODE_SOCKET_PATH"

Do I have to wait for the node to sync or something ?

Don’t think so.

The error explicitly says that it can’t find the environment variable that you are setting directly above it, which is kind of strange.

Do you see the variable if you do echo $CARDANO_NODE_SOCKET_PATH?
(As always: Such an export only has effect in the current shell session. To not have to do it every time, you would have to put the export in .bashrc or similar.)

I can see the variable from host

echo $CARDANO_NODE_SOCKET_PATH
/opt/cardano/cardano-node-ipc/node.socket

From inside container

bash-4.4# echo $CARDANO_NODE_SOCKET_PATH
/ipc/node.socket

Is the socket really there? ls -l /opt/cardano/cardano-node-ipc/node.socket from the host?

Yes it is

ls -l /opt/cardano/cardano-node-ipc/node.socket
srwxr-xr-x 1 root root 0 Aug 16 14:08 /opt/cardano/cardano-node-ipc/node.socket

I’m slowly getting out of ideas. …

Maybe try: bash -c 'echo $CARDANO_NODE_SOCKET_PATH'
(Important that those are single quotes not double.)

1 Like

It’s my fault , Bash variables are very handy , I placed variables in a file then load it by “source” command , now I set it with “export” and it works fine now. Thank you very much.

1 Like

You could also put the export in that file you are sourcing or do it in .bashrc or …

But it’s important to keep track if they are exported or not, which you cannot easily see by echo $VAR, but have to test in a sub-shell.