Running docker-container tests on circleCI

2019-04-15 17:15发布

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?

4条回答
太酷不给撩
2楼-- · 2019-04-15 17:54

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
查看更多
啃猪蹄的小仙女
3楼-- · 2019-04-15 18:03

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
查看更多
▲ chillily
4楼-- · 2019-04-15 18:04

@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
查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-04-15 18:15

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

查看更多
登录 后发表回答