Cannot connect to Docker container in build environment



I have a CircleCI job that first builds a Docker container image and then tests it by launching a corresponding container, and sending HTTP requests to it. However, it’s impossible to connect to the container on the published port. The connection is simply refused, and I can’t tell why. The same workflow works locally. Does anyone know why it doesn’t work to connect to a Docker container in a CircleCI job?

My CircleCI config looks like this:

version: 2
    - image: aknudsen/docker-with-node-python
    working_directory: ~/build
    - checkout
    - setup_remote_docker:
        version: 17.10.0-ce
    - run:
        name: Build Docker image
        command: |
          docker build -t$CIRCLE_SHA1 .
          docker tag$CIRCLE_SHA1
    - run:
        name: Test
        command: |
          npm install
          pip3 install -r requirements.txt
          npm test
    - deploy:
        name: Push Docker image
        command: |
          if [ "${CIRCLE_BRANCH}" == "release" ]; then
            docker login -u $QUAY_USER -p $QUAY_PASSWORD
            docker push$CIRCLE_SHA1
            docker push


Nevermind. I found out that with the docker executor it’s not possible to connect to containers, as they are executed remotely. By switching to the machine executor type, I was able to launch containers and connect to them.


That’s interesting. I know that you cannot use Docker volumes for this reason, but I have 12 services in a DC arrangement, and they all talk to each other over HTTP perfectly in CircleCI. I am using the Docker and not the Machine executor.


@halfer Sounds to me as if our use cases are different? What you’re doing should work since, if I understand correctly, your services exist in containers that communicate with each other. My use case is to launch a container and connect to it. This doesn’t work since the launched container is running remotely and as a result its published port won’t be available on localhost.


Ah, I see - you are connecting from the host to a started container. Fair enough. Could you copy the on-host stuff and put that in a container? Docker should then help you get communications working between each one.

Yep, correct!