Search code examples
dockersshdocker-composedocker-swarmcorda

Can't connect to corda node via ssh in docker


When trying to connect to running corda node via ssh the connection stuck and closing by timeout. Maybe someone can help with it? Looks like some issues with docker as the node works fine, just can't connect to it via ssh.

user@host:~$ ssh -v localhost -p 2222 -l users
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 2222.
debug1: connect to address 127.0.0.1 port 2222: Connection timed out
ssh: connect to host localhost port 2222: Connection timed out

Corda node is running by docker stack in swarm.

user@host:~$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                      PORTS
umifcjj1qutf        stack_users    replicated          1/1                 repository/node:latest   *:2222->2222/tcp, *:10006->10201/tcp

Service definition.

// docker-stack.yml
services:
    users:
        image: ${DOCKER_REGISTRY}/node:latest
        volumes:
            - users-persistance:/opt/corda/persistance:rw
        configs:
            -   source: users_config
                target: /etc/corda/node.conf
            -   source: users_certificate_nodekeystore
                target: /opt/corda/certificates/nodekeystore.jks
            -   source: users_certificate_sslkeystore
                target: /opt/corda/certificates/sslkeystore.jks
            -   source: users_certificate_truststore
                target: /opt/corda/certificates/truststore.jks
            -   source: users_add_node_info_1
                target: /opt/corda/additional-node-infos/nodeInfo-71FB94D0663EEB32054F04AA0F0554EA8AA2CA684CA9A75D2689F854BAC7C814
            -   source: users_add_node_info_2
                target: /opt/corda/additional-node-infos/nodeInfo-777DA369F066FE34BEDE3E6334A1006A4026A02DD76AFA798204BD015C9965DE
            -   source: users_network_parameters
                target: /opt/corda/network-parameters
        ports:
            - 10006:10201
            - 2222:2222

Note that everything works fine, I mean transactions are running ok in this node, but I can't just connect to the node.

The interesting fact is when running the node using docker-compose it works fine, I can connect to the node.

docker-compose.yml definition

users:
    build:
      context: ./blockchain/node
      target: api_platform_node_development
    image: ${DOCKER_REGISTRY}/node:latest
    volumes:
      - ./blockchain/build/nodes/Users/node.conf:/etc/corda/node.conf
      - ./blockchain/build/nodes/Users/certificates:/opt/corda/certificates
      - ./blockchain/build/nodes/Users/logs:/opt/corda/logs
      - ./blockchain/build/nodes/Users/persistence:/opt/corda/persistence
      - ./blockchain/build/nodes/Users/cordapps:/opt/corda/cordapps
      - ./blockchain/build/nodes/Users/network-parameters:/opt/corda/network-parameters
      - ./blockchain/build/nodes/Users/additional-node-infos:/opt/corda/additional-node-infos
      - ./blockchain/build/nodes/Users/drivers:/opt/corda/drivers
    ports:
      - 10006:10201
      - 2222:2222

Docker version 19.03.12, build 48a66213fe

docker-compose version 1.21.2, build a133471

docker-compose.yml version: '3.4'

UPD: node.conf

dataSourceProperties {
    dataSource {
        url="jdbc:h2:file:./persistence/persistence;DB_CLOSE_ON_EXIT=FALSE;WRITE_DELAY=0;LOCK_TIMEOUT=10000"
    }
}
detectPublicIp=false
devMode=false
myLegalName="O=Users,L=London,C=GB"
p2pAddress="users:10200"
rpcSettings {
    address="0.0.0.0:10201"
    adminAddress="0.0.0.0:10202"
}
security {
    authService {
        dataSource {
            type=INMEMORY
            users=[
                {
                    password=password
                    permissions=[
                        ALL
                    ]
                    user=users
                }
            ]
        }
    }
}
sshd {
    port=2222
}

UPD 2. node Dockerfile I'm using standard corda/corda-zulu-java1.8-4.4 docker image for nodes

FROM corda/corda-zulu-java1.8-4.4 AS api_platform_node_development

FROM corda/corda-zulu-java1.8-4.4 AS api_platform_node_production

COPY --from=repository/blockchain_build:latest /usr/blockchain/src/build/nodes/Users/cordapps /opt/corda/cordapps

Solution

  • hope it will be helpful for somebody else. The issue actually was with docker stack behavior that it doesn't publish ports outside by default, they are available only within swarm, so if you want to make them available outside the swarm you need to run additionally

    docker service update stack_users --publish-add 2222:2222