2

I run local DynamoDB and an app via docker-compose. Unfortunately I encounter an error when querying DynamoDB from the app:

Unable to execute HTTP request: Connect to dynamodb:80 [dynamodb/172.18.0.2] failed: Connection refused (Connection refused)

Here is how the docker-compose looks like:

version: "3"
services:
  dynamodb:
    image: "dynamodb-local:latest"
    container_name: app-dynamodb
    ports:
      - "80:8000"
  api:
    image: "app-backend:latest"
    container_name: app-api
    ports:
      - "5000:5000"
      - "5100:5100"
    environment:
      - DYNAMO_HOST=dynamodb:80

Here is how a Dockerfile for DynamoDB:

FROM openjdk:8-jre

ENV DYNAMODB_VERSION=latest

COPY .aws/ root/.aws/
COPY setup.sh setup.sh
COPY setup-stats.sh setup-stats.sh

RUN apt-get update && \
    apt-get install -y python python-pip && \
    pip --no-cache-dir install awscli && \
    apt-get clean all && \
    curl -O https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_${DYNAMODB_VERSION}.tar.gz && \
    tar zxvf dynamodb_local_${DYNAMODB_VERSION}.tar.gz && \
    rm dynamodb_local_${DYNAMODB_VERSION}.tar.gz

EXPOSE 8000

ENTRYPOINT java -Djava.library.path=. -jar DynamoDBLocal.jar --sharedDb -inMemory

UPDATE:

  1. I'm able to connect to dynamoDB JS shell from the host by http://localhost/shell
  2. I'm NOT able to connect to dynamoDB from the app container:
wget dynamodb/shell
Connecting to dynamodb (172.18.0.2:80)
wget: can't connect to remote host (172.18.0.2): Connection refused
  1. The app is written on Scala and uses Scanamo for interaction with DynamoDB
1
  • did you try to connect to dynamo on port 8000?. I'm not sure that you be able to connect to dynamo on port 80 from a container in the same network, because the port 80 is to expose the service to the external network (that's the reason that you are able to connect from the host machine). Instead of this, try to change the DYNAMO_HOST env variable to dynamodb:8000
    – mauricubo
    Feb 13, 2019 at 21:38

2 Answers 2

3

The problem was in missed DYNAMO_ACCESS_KEY and DYNAMO_SECRET_KEY Despite the dyanmoDB is local and runs in-memory, it requires access_key and secret_key values any way

Furthermore, these values should NOT be empty! So set there anything you want, like "foo" or "bar".

2

I can see that there is no communication between the DB and the API container. There is a Docker Links Key-Value pair which will help. Please find the updated docker-compose file.

version: "3"
services:
  dynamodb:
    image: "dynamodb-local:latest"
    container_name: app-dynamodb
    ports:
      - "80:8000"
  api:
    image: "app-backend:latest"
    container_name: app-api
    ports:
      - "5000:5000"
      - "5100:5100"
    links:
      - dynamodb
    environment:
      - DYNAMO_HOST=dynamodb:80

This may be the solution Please let me know the Status.

1
  • My problem was solved by the comment, I posted above ;) Feb 14, 2019 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.