Docker Community Forums

Share and learn in the Docker community.

Docker compose cant connect to other services

I have a docker compose file for my visual studio api project, the project has dependencies on AWS dynamoDb and Elasticsearch, I am using two images for these dependent services:

version: '3.2'

services:
  api:
    image: api
    build:
      context: ./src/API
      dockerfile: Dockerfile
    depends_on:
      - "dynamodb"
      - "api.provisioner"
    environment:
      AWS_ACCESS_KEY_ID: dummy
      AWS_SECRET_ACCESS_KEY: dummy
    ports:
      - "32769:80"
  api.provisioner:
    image: api.provisioner
    build:
      context: ./src/API.Provisioner
      dockerfile: Dockerfile
    depends_on:
      - "dynamodb"
      - "elasticsearch"
    environment:
      AWS_ACCESS_KEY_ID: dummy
      AWS_SECRET_ACCESS_KEY: dummy
  dynamodb:
    image: cnadiminti/dynamodb-local
    ports:
      - "8000:8000"
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.1.1
    environment:
      discovery.type: single-node
    ports:
      - "9200:9200"
      - "9300:9300"

I can see in the logs that docker compose successfully deploys these containers:

farha@DESKTOP-J9B5HJG MINGW64 ~/OneDrive/Documents/api
$ docker ps
CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS                                            NAMES
56aeaef0c700        api:dev                       "tail -f /dev/null"      6 minutes ago       Up 6 minutes        0.0.0.0:32769->80/tcp, 0.0.0.0:32774->80/tcp     						dockercompose1623617006322596464_api_1
4a568b2f2258        api.provisioner:dev           "tail -f /dev/null"      6 minutes ago       Up 6 minutes                                                         						dockercompose1623617006322596464_api.provisioner_1
5306a85f014a        cnadiminti/dynamodb-local                             "/docker-entrypoint.…"   6 minutes ago       Up 6 minutes        0.0.0.0:8000->8000/tcp                           dockercompose1623617006322596464_dynamodb_1
ae80d7fdb6f9        docker.elastic.co/elasticsearch/elasticsearch:6.1.1   "/usr/local/bin/dock…"   6 minutes ago       Up 6 minutes        0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   dockercompose1623617006322596464_elasticsearch_1

but am not able to access the different containers from within my dependent app and get a TimeOutException, I also get this Exception when trying to connect to the DynamoDb container:

C:\Users\farha>aws dynamodb create-table --table-name myTable --attribute-definitions AttributeName=id,AttributeType=S --key-schema AttributeName=id,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 --endpoint-url http://0.0.0.0:8000

Could not connect to the endpoint URL: "http://0.0.0.0:8000/"

when I try to ping these endpoints from my command line they timeout, and it also happens from within my dependent app.

the urls that I use are:

{
  "AWS": {
    "DynamoDB": {
      "ServiceURL": "http://dynamodb:8000"
    }
  },
  "ElasticSearch": {
    "URL": "http://elasticsearch:9200"
  },
  "Data": {
    "DynamoDbTablePrefix": "local-db-"
  }
}