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

**URL:** <https://discuss.aerospike.com/t/cant-connect-to-aerospike-server-in-docker-compose-yml-python-client/7691>\
**Category:** General Discussion\
**Created:** [July 28, 2020, 11:09am UTC](https://discuss.aerospike.com/t/cant-connect-to-aerospike-server-in-docker-compose-yml-python-client/7691 "2020-07-28T11:09:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![funcelot](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/funcelot/32/1481_2.png) [@funcelot](https://discuss.aerospike.com/u/funcelot)\
**Post date:** [July 28, 2020, 11:09am UTC](https://discuss.aerospike.com/t/cant-connect-to-aerospike-server-in-docker-compose-yml-python-client/7691/1 "2020-07-28T11:09:49Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Albot](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/albot/32/2076_2.png) [@Albot](https://discuss.aerospike.com/u/Albot)\
**Post date:** [July 30, 2020, 12:17am UTC](https://discuss.aerospike.com/t/cant-connect-to-aerospike-server-in-docker-compose-yml-python-client/7691/2 "2020-07-30T00:17:34Z")

</div>

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’ ?

---

<div class="post-metadata">

**Author:** ![funcelot](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/funcelot/32/1481_2.png) [@funcelot](https://discuss.aerospike.com/u/funcelot)\
**Post date:** [July 30, 2020, 12:19am UTC](https://discuss.aerospike.com/t/cant-connect-to-aerospike-server-in-docker-compose-yml-python-client/7691/3 "2020-07-30T00:19:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Albot](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/albot/32/2076_2.png) [@Albot](https://discuss.aerospike.com/u/Albot)\
**Post date:** [July 30, 2020, 12:20am UTC](https://discuss.aerospike.com/t/cant-connect-to-aerospike-server-in-docker-compose-yml-python-client/7691/4 "2020-07-30T00:20:14Z")

</div>

i dont understand

---

<div class="post-metadata">

**Author:** ![funcelot](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/funcelot/32/1481_2.png) [@funcelot](https://discuss.aerospike.com/u/funcelot)\
**Post date:** [July 30, 2020, 12:23am UTC](https://discuss.aerospike.com/t/cant-connect-to-aerospike-server-in-docker-compose-yml-python-client/7691/5 "2020-07-30T00:23:50Z")

</div>

i have aerospike server, like this [Docker Hub](https://hub.docker.com/r/aerospike/aerospike-server/dockerfile/) i have a documentation [https://aerospike.com/docs/client/python/index.html](https://aerospike.com/docs/client/python/index.html) and i cant connect to aerospike, cause sample in documentation is not working

---

<div class="post-metadata">

**Author:** ![lucien](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/lucien/32/2065_2.png) [@lucien](https://discuss.aerospike.com/u/lucien)\
**Post date:** [July 31, 2020, 1:06am UTC](https://discuss.aerospike.com/t/cant-connect-to-aerospike-server-in-docker-compose-yml-python-client/7691/6 "2020-07-31T01:06:21Z")

</div>

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'}

```

---

<div class="post-metadata">

**Author:** ![funcelot](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/funcelot/32/1481_2.png) [@funcelot](https://discuss.aerospike.com/u/funcelot)\
**Post date:** [August 1, 2020, 4:16am UTC](https://discuss.aerospike.com/t/cant-connect-to-aerospike-server-in-docker-compose-yml-python-client/7691/7 "2020-08-01T04:16:50Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/system/32/2274_2.png) [@system](https://discuss.aerospike.com/u/system)\
**Post date:** [August 7, 2020, 4:16am UTC](https://discuss.aerospike.com/t/cant-connect-to-aerospike-server-in-docker-compose-yml-python-client/7691/8 "2020-08-07T04:16:52Z")

</div>

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