Cannot connect to Docker container in build environment

docker

#1

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
jobs:
  build:
    docker:
    - image: aknudsen/docker-with-node-python
    working_directory: ~/build
    steps:
    - checkout
    - setup_remote_docker:
        version: 17.10.0-ce
    - run:
        name: Build Docker image
        command: |
          docker build -t quay.io/socialfoodie/web:$CIRCLE_SHA1 .
          docker tag quay.io/socialfoodie/web:$CIRCLE_SHA1 quay.io/socialfoodie/web:latest
    - 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 quay.io
            docker push quay.io/socialfoodie/web:$CIRCLE_SHA1
            docker push quay.io/socialfoodie/web:latest
          fi

#2

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.


#3

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.


#4

@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.


#5

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!


#6