TLS Error when trying to use Docker-Compose

I’ve been fighting to get my docker-compose services to run in circleci so that I can have them test and deploy automatically.

I got it to work after much todo. I had to install docker-compose via curl instead of through PIP because it kept not finding it, but when trying to use docker-compose to bring up all my services I get a TLS error oddly enough.

Here’s the error:

Digest: sha256:3d161cb77f65397f11afa6781e1031cc45e243c50c007a6a8b2c20c095e17173
Status: Downloaded newer image for docker/compose:1.22.0
^@^@Traceback (most recent call last):
  File "bin/docker-compose", line 6, in <module>
  File "compose/cli/main.py", line 71, in main
  File "compose/cli/main.py", line 124, in perform_command
  File "compose/cli/command.py", line 38, in project_from_options
  File "compose/cli/docker_client.py", line 84, in tls_config_from_options
  File "site-packages/docker/tls.py", line 81, in __init__
docker.errors.TLSParameterError: Path to a certificate and key files must be provided through the client_config param. TLS configurations should map the Docker CLI client configurations. See https://docs.docker.com/engine/articles/https/ for API details.
[8] Failed to execute script docker-compose
Exited with code 255

I’m not exactly sure what TLS certs have to do with my current setup as I’m just trying to deploy to circleci.

Here is my circleci config file:

version: 2
jobs:
  build:
    working_directory: /app
    docker:
      - image: docker:17.05.0-ce-git
    steps:
      - checkout
      - setup_remote_docker
      - restore_cache: # restores saved depdendency cache if Branch key template or requirements haven't changed
          keys: 
            - v1-{{ .Branch }}-{{ checksum "requirements/test.txt" }}
            - v1-{{ .Branch }}-dependencies        
      - run:
          name: Install dependencies
          command: |
            apk update
            apk del python2
            apk add sudo curl curl-dev bash
            apk add --no-cache python3
            apk add postgresql-libs
            apk add --virtual .build-deps gcc musl-dev postgresql-dev libpq
            apk add --no-cache py3-pip
            apk add --no-cache py-virtualenv
            apk add --no-cache python3-dev
            apk add --no-cache py3-psycopg2
            python3 -m venv venv
            . venv/bin/activate
            pip3 install --upgrade pip setuptools
            pip3 install -r requirements/test.txt
            apk --purge del .build-deps
      - run:
          name: Install docker-compose with curl
          command: |
            sudo curl -L --fail https://github.com/docker/compose/releases/download/1.22.0/run.sh -o /usr/local/bin/docker-compose
            sudo chmod +x /usr/local/bin/docker-compose
      - save_cache: # save dependency cache
          key: v1-{{ .Branch }}-{{ checksum "requirements/test.txt" }}
          paths:
            - ./venv
      - restore_cache: # restore saved docker image chache if hasn't changed
          keys:
            - v1-{{ .Branch }}
          paths:
            - /caches/app.tar
      - run:
          name: Load Docker image layer cache
          command: |
            set +o pipefail
            docker load -i /caches/app.tar | true
      - run:
          name: Build application Docker image
          command: |
            docker build --cache-from=app -t app .
      - run:
          name: Save Docker image layer cache
          command: |
            mkdir -p /caches
            docker save -o /caches/app.tar app
      - save_cache: # save docker image cache
          key: v1-{{ .Branch }}-{{ epoch }}
          paths:
            - /caches/app.tar
      - run:
          name: Run compose with test config
          command: |
            docker-compose -d -f docker-compose.test.yml up
      - run: 
          name: Make test-results directory
          command: |
            mkdir -p /test-results
      - run:
          name: Run tests
          command: |
            . venv/bin/activate
            python3 manage.py test
      - store_test_results:
          path: test-results
      - store_artifacts:
          path: test-results

and here is my compose file:

version: "3.2"
services:
  app:
    build:
      context: .
      args:
        requirements: requirements/test.txt
    dockerfile: Dockerfile.test
    environment:
      - DJANGO_SETTINGS_MODULE=sasite.settings.test
      - PYTHONDONTWRITEBYTECODE=1
    volumes:
      - ./:/app
    networks:
      - main
    depends_on:
      - db
  db:
    image: postgres:10.1-alpine
    environment:
      POSTGRES_DB: sasite_test_db
      POSTGRES_USER: pguser
      POSTGRES_PASSWORD: pguser123
    ports:
      - "5432:5432"
    networks:
      - main
  nginx:
    image: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
      - ./static:/usr/share/nginx/sasite/static
    ports:
      - "80:80"
    networks:
      - main
    depends_on:
      - app

I’m not sure if I’m using compose wrong with circleci or not but I don’t see how else I can set up all my services that go with my custom docker image for my app without using compose.

Any guidance would be appreciated.

You can just use the DC image directly, to save you having to install it:

image: docker/compose:1.20.1

I used to install it with pip, but this way is easier.

So just replace the docker git with docker compose ? Will it have git/pip installed already?

Please don’t add signatures when replying to the board. Replying by email is fine, but it’s worth removing everything that is not germane to your message, as if you were replying via the web app.

To swap to the Docker Compose image, replace it in your docker section. I have this:

version: 2
jobs:
  build:
    working_directory: /app
    docker:
      - image: docker/compose:1.20.1

Of course, you also need to remove the manual installation of DC later on in your config.

Sorry about that I was on the train and replied really quickly.

I managed to make it work with a custom image but I would rather use your solution. Seems the answer is is no it doesn’t have git, ssh, or pip installed. How would you suggest installing pip/python3 on the image? The image isn’t based on alpine or ubuntu/debian so I’m unsure how to install them efficiently.

That is quite likely. You can install them though. As you correctly have it in your above YAML file, use apk add with the things you need.

If you do need to install DC via pip, I used to do it this way:

      - run:
          name: Install Docker Compose
          command: |
            set -x
            apk --update add 'py-pip==9.0.0-r1'
            pip install 'docker-compose==1.13.0'

However, that broke, because the items I asked for are too old to be in the repo. You’d need to fix them. This is why I moved over to the DC image.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.