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

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
  client = aerospike.client(config).connect()
  import sys
  print("failed to connect to the cluster with", config['hosts'])

Docker file for micro-service

$ cat Dockerfile 
# Aerospike Python client container

FROM ubuntu:18.04

  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/"]

output from within the micro-service container:

root@05cddf2ddbb9:/code# python 
{'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/
{'age': 32, 'name': 'John Doe'}