Docker Community Forums

Share and learn in the Docker community.

Unable to connect to docker in docker/compose:1.25.0-rc2-alpine image

This may be a bit too specific, but hoping someone can help provide me some direction. I’m using DynamoDB for the first time for work, and setup the local docker image. Locally it works great, including a test file I created. Then I pushed it up and it ran through our CI (GitLab). I see the docker container being created:

$ docker-compose up -d
Creating network "user-video-rekognition-lambda_default" with the default driver
Pulling dynamodb-local (amazon/dynamodb-local:latest)...
latest: Pulling from amazon/dynamodb-local
Digest: sha256:bdd26570dc0e0ae49e1ea9d49ff662a6a1afe9121dd25793dc40d02802e7e806
Status: Downloaded newer image for amazon/dynamodb-local:latest
Creating dynamodb-local ... 

However, when the script tries to connect, Could not connect to the endpoint URL: "http://localhost:8000/" . localhost:8000 is what works locally and is set up for by the docker compose. I can’t figure out what IP it wants me to connect to, or how to debug this. As it’s a CI, I can’t SSH in and pop out values. I tried as well, in case. I donno if anyone has any thoughts? It’s run on a base image of docker/compose:1.25.0-rc2-alpine , but I can’t find anything that suggests that that uses a different IP for docker?

how is this related to amazon/dynamodb-local:latest?

Please share the relavant information that helps to actualy understand not only what you try to achive, but also how you try to do it (like exact commands and compose.yml files).

As I said above, the docker/compose image is the base the CI is running on, and the dynamo db image is being brought up within that.

Here’s my compose:

version: '3'
        command: "-jar DynamoDBLocal.jar -sharedDb -optimizeDbBeforeStartup -dbPath ./data"
        image: "amazon/dynamodb-local:latest"
        container_name: dynamodb-local
            - "8000:8000"
            - "./database:/home/dynamodblocal/data"
        working_dir: /home/dynamodblocal

And the CI is running, trimmed down:

image: docker/compose:1.25.0-rc2-alpine
  - docker:dind

  - apk update && apk add python3-dev curl-dev bash zip libzip-dev gcc build-base libffi-dev
  - pip3 install --upgrade pip
  - pip3 install awscli pipenv
  - pipenv install --system --deploy
  - docker-compose up -d
  - docker info

So this boils down to a “I can not access the docker:dind container from my docker-compose container”.

You might want to Incorporate suggestions from Use Docker to build Docker images | GitLab to your first block:

image: docker/compose:1.25.0-rc2-alpine
  # When using dind service, you must instruct Docker to talk with
  # the daemon started inside of the service. The daemon is available
  # with a network connection instead of the default
  # /var/run/docker.sock socket.
  DOCKER_HOST: tcp://docker:2376
  - docker:dind

This should hopefully do the trick. Oh and make sure the docker:dind container runs in privileged mode (I assume this is the default behavior) …

Thanks for the suggestion. I had seen that, but wasn’t sure it applied since we’re not using the docker image directly. I tried it and it fails with:

Couldn't connect to Docker daemon at http://docker:2376 - is it running?

As I mentioned, the image comes up according to the logs, but the script I run can’t access it.

The problem is obvious: the compose container is not able to communicate with the docker engine in your dind container.

The solution needs some refinement. The docs indicate that everything after the : get stripped away. So “docker” actualy is the porper hostname to use in DOCKER_HOST. Now the question is “what makes the dind image bind the docker engine to the tcp port”. As I am not using this sort of setup, I am leaving this for someone else to answer. Good luck!