Docker images unable to talk to each other

398 Views Asked by At

I am trying to make two images depend on each other. One acts as the master and the other one is a worker. Here are the two Dockerfiles

FROM cubejs/cubestore:v0.31.58-arm64v8
ENV CUBESTORE_WORKERS=cubestore_worker_1:9001
ENV CUBESTORE_META_PORT=9999
ENV CUBESTORE_SERVER_NAME=cubestore_router:9999

Dockerfile 2

FROM cubejs/cubestore:v0.31.58-arm64v8
ENV CUBESTORE_SERVER_NAME=cubestore_worker_1:9001
ENV CUBESTORE_WORKER_PORT=9001
ENV CUBESTORE_META_ADDR=cubestore_router:9999
ENV CUBESTORE_WORKERS=cubestore_worker_1:9001

I am building the images with docker build -f path/Dockerfile . Running them with the sha256 that is generated after every build using docker run imageid.

I want cubestore_worker_1 to talk to cubestore_router image. I tried the following but I still don't have it working

docker network create my-network
docker run image1id --network my-network
docker run image2id --network my-network

I am really struggling with this. Any idea how I can achieve this? TIA

2

There are 2 best solutions below

0
boomchickawawa On BEST ANSWER

I had to basically change the values CUBESTORE_SERVER_NAME to the IPv4 address in the docker inspect container output and re run the docker run --network network name conatainername commands and it works like a charm!

0
Stuart Auld On

You should use docker compose... from the Cubestore docs (https://cube.dev/docs/product/caching/running-in-production)

version: "2.2"
services:
  cubestore_router:
    restart: always
    image: cubejs/cubestore:latest
    environment:
      - CUBESTORE_SERVER_NAME=cubestore_router:9999
      - CUBESTORE_META_PORT=9999
      - CUBESTORE_WORKERS=cubestore_worker_1:9001,cubestore_worker_2:9001
      - CUBESTORE_REMOTE_DIR=/cube/data
    volumes:
      - .cubestore:/cube/data
  cubestore_worker_1:
    restart: always
    image: cubejs/cubestore:latest
    environment:
      - CUBESTORE_SERVER_NAME=cubestore_worker_1:9001
      - CUBESTORE_WORKER_PORT=9001
      - CUBESTORE_META_ADDR=cubestore_router:9999
      - CUBESTORE_WORKERS=cubestore_worker_1:9001,cubestore_worker_2:9001
      - CUBESTORE_REMOTE_DIR=/cube/data
    depends_on:
      - cubestore_router
    volumes:
      - .cubestore:/cube/data
  cubestore_worker_2:
    restart: always
    image: cubejs/cubestore:latest
    environment:
      - CUBESTORE_SERVER_NAME=cubestore_worker_2:9001
      - CUBESTORE_WORKER_PORT=9001
      - CUBESTORE_META_ADDR=cubestore_router:9999
      - CUBESTORE_WORKERS=cubestore_worker_1:9001,cubestore_worker_2:9001
      - CUBESTORE_REMOTE_DIR=/cube/data
    depends_on:
      - cubestore_router
    volumes:
      - .cubestore:/cube/data
  cube:
    image: cubejs/cube:latest
    ports:
      - 4000:4000
    environment:
      - CUBEJS_CUBESTORE_HOST=cubestore_router
    depends_on:
      - cubestore_router
    volumes:
      - .:/cube/conf