Cant connect to aerospike-server in docker-compose.yml (Python client)

I have docker-compose.yml

version: '3.5'

services:

  micro-service:

    build:

      context: .

      dockerfile: Dockerfile

    ports:

      - 5080:5080

    environment:

      AEROSPIKE_HOST: aerospike

      AEROSPIKE_PORT: 3000

      APP_PORT: 5080

    volumes:

      - ./:/code

    restart: always

    networks:

      - app_net

  aerospike:

    image: aerospike/aerospike-server

    ports:

      - 127.0.0.1:3000:3000

      - 127.0.0.1:3001:3001

      - 127.0.0.1:3002:3002

      - 127.0.0.1:3003:3003

    environment:

      NAMESPACE: test

    networks:

      - app_net

networks:

  app_net:

    internal: false

i can’t connect usnig this code

    app.aerospike = aerospike.client(app.config['AEROSPIKE_CONFIG']).connect()

(-10, ‘Failed to connect’, ‘src/main/aerospike/as_cluster.c’, 254, False)

Probably something not exposed right from docker. Try to use telnet or a simple socket test to figure out the issue. Where is the code running from? What is ‘AEROSPIKE_CONFIG’ ?

none env vars is set, just default docker image and connection string from aerospike documentation

i dont understand

i have aerospike server, like this Docker Hub i have a documentation https://aerospike.com/docs/client/python/index.html and i cant connect to aerospike, cause sample in documentation is not working

Which ip address are you using from the micro-service container to connect to the aerospike container? I don’t think you can use the loopback ip within the microservice container to talk over port 3000 to the other container.

Seems to work with the example you mentioned and using the “aerospike” hostname.

# Configure the client
config = {
  'hosts': [ ('aerospike', 3000) ]
}

# Create a client and connect it to the cluster
try:
  client = aerospike.client(config).connect()
except:
  import sys
  print("failed to connect to the cluster with", config['hosts'])
  sys.exit(1)

Docker file for micro-service

$ cat Dockerfile 
#
# Aerospike Python client container

FROM ubuntu:18.04

RUN \
  apt-get update -y \
  && apt-get install python-dev vim net-tools iproute2 telnet -y \
  && apt-get install libssl-dev -y \
  && apt-get install python-pip -y \
  && apt-get install zlib1g-dev -y \
  && apt-get install -y wget python lua5.2 gettext-base \
  && pip install aerospike \
  && apt-get purge -y \
  && apt autoremove -y 

# Execute the run script in foreground mode
#ENTRYPOINT ["python"]
#CMD ["/code/test.py"]

output from within the micro-service container:

root@05cddf2ddbb9:/code# python  test.py 
{'age': 32, 'name': 'John Doe'}

or from running docker run and attaching to bridge network

docker run -ti -v `pwd`:/code --rm --net test-compose_app_net testpython python /code/test.py
{'age': 32, 'name': 'John Doe'}

Thank you!

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.