Docker-compose for local dev environment

Hi,
I’m trying to set up a docker-compose.yml with a simple local network node-farmer environment so I can run queries against it using subspace.js. I have this docker-compose file so far:

version: "3.7"
services:
  node:
    image: ghcr.io/subspace/node:gemini-1b-2022-aug-17
    volumes:
      - node-data:/var/subspace:rw
    ports:
      - "0.0.0.0:9955:9955"
    restart: unless-stopped
    command:
      [
        "--dev",
        "--tmp",
        "--force-authoring",
        "--execution",
        "wasm",
        "--pruning",
        "1024",
        "--keep-blocks",
        "1024",
        "--port",
        "9955",
        "--rpc-cors",
        "all",
        "--rpc-methods",
        "safe",
        "--unsafe-ws-external",
        "--validator",
        "--name",
        "local-test-node"
      ]
    healthcheck:
      timeout: 5s
      interval: 30s
      retries: 5
  farmer:
    depends_on:
      node:
        condition: service_healthy
    image: ghcr.io/subspace/farmer:gemini-1b-2022-aug-17
    volumes:
      - farmer-data:/var/subspace:rw
    restart: unless-stopped
    ports:
      - "0.0.0.0:9944:9944"
    command:
      [
        "--base-path",
        "/var/subspace",
        "farm",
        "--node-rpc-url",
        "ws://node:9944",
        "--ws-server-listen-addr",
        "0.0.0.0:9955",
        "--reward-address",
        "5EnzMQs2srMSMFjCVvgdbBJN6hgcL8PQLZVMAzRs7qYbr27e",
        "--plot-size",
        "2G"
      ]
volumes:
  node-data:
  farmer-data:

docker ps command outputs

CONTAINER ID   IMAGE                                           COMMAND                  CREATED              STATUS                    PORTS                    NAMES
3bd9a6c600b2   ghcr.io/subspace/farmer:gemini-1b-2022-aug-17   "/subspace-farmer --…"   29 seconds ago       Up 28 seconds             0.0.0.0:9944->9944/tcp   subspace_farmer_1
7c3792a87db5   ghcr.io/subspace/node:gemini-1b-2022-aug-17     "/subspace-node --de…"   About a minute ago   Up 59 seconds (healthy)   0.0.0.0:9955->9955/tcp   subspace_node_1

But in the initial logs of the node cli terminal I get this:

node_1    | 2022-08-24 17:29:48 [PrimaryChain] Running JSON-RPC HTTP server: addr=127.0.0.1:9933, allowed origins=None    
node_1    | 2022-08-24 17:29:48 [PrimaryChain] Running JSON-RPC WS server: addr=0.0.0.0:9944, allowed origins=None  

My problem Is I cannot access the web sockets via ws://localhost:9955 or ws://localhost:9944

any help appreciated…

2 Likes

OK, after a bit of a struggle, I got this to work and accept connections locally. The issue is

"--rpc-cors",
        "all",

does not work, so you need to specify the local addresses instead of using all.

Here is the updated docker-compose:

version: "3.7"
services:
  node:
    image: ghcr.io/subspace/node:gemini-1b-2022-aug-17
    volumes:
      - node-data:/var/subspace:rw
    ports:
      - "9944:9944"
      # - "0.0.0.0:9955:9955"
    restart: unless-stopped
    command:
      [
        "--dev",
        "--tmp",
        "--force-authoring",
        "--execution",
        "wasm",
        "--pruning",
        "1024",
        "--keep-blocks",
        "1024",
        "--port",
        "9955",
        # "--ws-external",
        "--unsafe-rpc-external",
        "--rpc-cors",
        "ws://localhost,http://localhost,ws://node,http://node,ws://farmer,http://farmer,all,127.0.0.1,localhost",
        "--rpc-methods",
        "safe",
        "--unsafe-ws-external",
        "--validator",
        "--name",
        "local-test-node"
      ]
    healthcheck:
      timeout: 5s
      interval: 30s
      retries: 5
  farmer:
    depends_on:
      node:
        condition: service_healthy
    image: ghcr.io/subspace/farmer:gemini-1b-2022-aug-17
    volumes:
      - farmer-data:/var/subspace:rw
    restart: unless-stopped
    ports:
      - "0.0.0.0:9955:9955"
    command:
      [
        "--base-path",
        "/var/subspace",
        "farm",
        "--node-rpc-url",
        "ws://node:9944",
        "--ws-server-listen-addr",
        "0.0.0.0:9955",
        "--reward-address",
        "5EnzMQs2srMSMFjCVvgdbBJN6hgcL8PQLZVMAzRs7qYbr27e",
        "--plot-size",
        "4G"
      ]
volumes:
  node-data:
  farmer-data:

Might be useful to put it in the documentation for development, specially if the dev wants to work only the frontend or API interactions.

2 Likes

Awesome glad you were able to figure this out! I will get some of these details added to the documentation thank you!