Docker - ssh key

In case to use ssh-keys device access in docker you need to export the keys from the Docker host to make them persistent.

Docker run

  1. Put the keys into /var/xormon-ng/ssh-keys on the Docker host and make sure rights are correct
    ls -la  /var/xormon-ng/ssh-keys
      drwx------   2 root root   76 Jan 30  2023 .
      dr-xr-x---. 26 root root 4096 Jan 17 12:34 ..
      -rw-------   1 root root  419 Jan 17 12:34 id_ed25519
      -rw-r--r--   1 root root  104 Jan 17 12:34 id_ed25519.pub
    
  2. Test connection to the device, user your own device user and hostname/IP
    ssh -i  /var/xormon-ng/ssh-keys/id_ed25519 <device user>@<device IP/hostname>
    
  3. Map /var/xormon-ng/ssh-keys to /root/.ssh/ into the container as per bellow
    docker run --init -d --name xormon --ulimit core=0 -p 8443:8443 \
    -v /var/xormon-ng/files:/app/server-nest/files \
    -v /var/xormon-ng/ssh-keys:/root/.ssh \
    --link timescaledb:timescaledb --env-file ./xormon-ng.env xorux/xormon-ng:latest

Docker compose

  1. Put the keys into the directory ./ssh-keys where is docker-compose.yml on the Docker host and make sure rights are correct
    ls -la  ./ssh-keys
      drwx------   2 root root   76 Jan 30  2023 .
      dr-xr-x---. 26 root root 4096 Jan 17 12:34 ..
      -rw-------   1 root root  419 Jan 17 12:34 id_ed25519
      -rw-r--r--   1 root root  104 Jan 17 12:34 id_ed25519.pub
    
  2. Test connection to the device, user your own device user and hostname/IP
    ssh -i  ./ssh-keys/id_ed25519 <device user>@<device IP/hostname>
    
  3. Map ./ssh-keys to /root/.ssh/ into the container as per bellow
    services:
      timescaledb:
        image: timescale/timescaledb:latest-pg16
        init: true
        restart: unless-stopped
        ulimits:
          core: 0
        environment:
          - POSTGRES_USER=${DB_USERNAME}
          - POSTGRES_PASSWORD=${DB_PASSWORD}
          - TZ=${TZ}
        volumes:
          - ./data:/var/lib/postgresql/data
        ## uncomment if you want to have Postgres (TSDB) port opened on host
        # ports:
        #  - '5432:5432'
      xormon:
        image: xorux/xormon-ng:latest
        init: true
        restart: unless-stopped
        ulimits:
          core: 0
        depends_on:
          - timescaledb
        env_file: .env
        volumes:
          - ./files:/app/server-nest/files
          - ./ssh-keys:/root/.ssh
        ports:
          - ${APP_PORT}:${APP_PORT}
          - 8162:8162