Running docker-container tests on circleCI

拜拜、爱过 提交于 2020-01-01 19:31:24

问题


I have created some integration tests for my open-sourced code and I am looking for a publicly accessible CI service to host them. As Travis-CI has to small quotas for all my containers, I think I will use CircleCI. This is my cirle.yml:

machine:
    services:
        - docker
dependencies:
    override:
        - pip install docker-compose
test:
    override:
        - cd integration-tests && docker-compose run --rm runner

However after running this I get error message "client and server don't have same version (client : 1.18, server: 1.16)" What is my problem?


回答1:


@zefciu This config just worked for me

machine:
  services:
    - docker

dependencies:
  override:
    - sudo pip install -U docker-compose==1.3.3

test:
  override:
    - docker-compose -f <compose-file> build && docker-compose -f <compose-file> up



回答2:


With extensive help of Support and some trial and error I found two problems with my configuration:

  1. The default docker version on CircleCI is incompatible with newest docker-compose.
  2. Removal of containers is impossible, so the --rm flag will cause the build to go red even if tests pass.

The correct configuration therefore will look like this:

 machine:
        services:
            - docker
        pre:
            - sudo curl -sSL https://get.docker.com/ | sh
    dependencies:
        override:
            - pip install docker-compose
    test:
        override:
            - cd integration-tests && docker-compose run runner



回答3:


UPDATE: It's not needed anymore, CircleCI has Docker v1.8.2 by default now

You can update docker version like this:

machine:
  services:
    - docker
  pre:
    - docker --version
    - sudo curl -L -o /usr/bin/docker 'http://s3-external-1.amazonaws.com/circle-downloads/docker-1.8.2-circleci'
    - sudo chmod 0755 /usr/bin/docker
    - docker --version

You can replace 1.8.2 in the amazon S3 link to the version you want




回答4:


you can do this by using --net=host when running your container, this will allow you to access Circle CI services via localhost. With this you don't need to use docker-compose. Circle CI provides most services for you.

machine:
  services:
    - docker
    - mysql
    - redis

  ...

  test:
    override:
      - |
          docker run \
            --net=host \
            --env MYSQL_HOST=localhost \
            --env MYSQL_PORT=3306 \
            --env MYSQL_DATABASE=circle_test \
            --env MYSQL_USERNAME=ubuntu \
            --env REDIS_HOST=localhost \
            --env REDIS_PORT=$REDIS_PORT \
            my/container runner


来源:https://stackoverflow.com/questions/31213195/running-docker-container-tests-on-circleci

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!