Docker Compose基于Gitlab CI - 管道错误

时间:2017-07-24 12:13:31

标签: docker docker-compose gitlab-ci gitlab-ci-runner

问题

我用 docker compose 制作了一个项目。它适用于localhost。我想用这个基础来测试或分析Gitlab Runner的代码。我解决了很多问题,比如安装docker compose,运行和构建选定的容器并在容器中运行命令。第一份工作跑了并成功(!!!),但是之前的工作失败了#34; before_script":

  

无法在unix:///var/run/docker.sock上连接到Docker守护程序。 docker守护程序是否在运行?   ...
  来自守护程序的错误响应:冲突   ...
  来自守护程序的错误响应:冲突。

我不明白为什么。我做错了什么?我再说一遍:管道的第一份工作与"成功" 消息一起运行良好!管道的每个其他工作都失败了。

完整输出:

Running with gitlab-ci-multi-runner 9.4.0 (ef0b1a6)
  on XXX Runner (fdc0d656)
Using Docker executor with image docker:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image docker:dind ID=sha256:5096e5a0cba00693905879b09e24a487dc244b56e8e15349fd5b71b432c6ec9ffor docker service...
ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Will be retried in 3s ...
Using Docker executor with image docker:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image docker:dind ID=sha256:5096e5a0cba00693905879b09e24a487dc244b56e8e15349fd5b71b432c6ec9f for docker service...
ERROR: Preparation failed: Error response from daemon: Conflict. The container name "/runner-fdc0d656-project-35-concurrent-0-docker" is already in use by container "80918876ffe53e33ce1f069e6e545f03a15469af6596852457f11dbc7a6c5b58". You have to remove (or rename) that container to be able to reuse that name.
Will be retried in 3s ...
Using Docker executor with image docker:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image docker:dind ID=sha256:5096e5a0cba00693905879b09e24a487dc244b56e8e15349fd5b71b432c6ec9f for docker service...
ERROR: Preparation failed: Error response from daemon: Conflict. The container name "/runner-fdc0d656-project-35-concurrent-0-docker" is already in use by container "80918876ffe53e33ce1f069e6e545f03a15469af6596852457f11dbc7a6c5b58". You have to remove (or rename) that container to be able to reuse that name.
Will be retried in 3s ...
ERROR: Job failed (system failure): Error response from daemon: Conflict. The container name "/runner-fdc0d656-project-35-concurrent-0-docker" is already in use by container "80918876ffe53e33ce1f069e6e545f03a15469af6596852457f11dbc7a6c5b58". You have to remove (or rename) that container to be able to reuse that name.

文件

.gitlab-ci.yml

# Select image from https://hub.docker.com/r/_/php/
image: docker:latest

# Services
services:
    - docker:dind

stages:
    - build
    - test
    - deploy

cache:
    key: ${CI_BUILD_REF_NAME}
    untracked: true
    paths:
        - vendor
        - var

variables:
    DOCKER_CMD: docker exec --user user bin
    COMPOSE_HTTP_TIMEOUT: 300

before_script:
    - apk add --no-cache py-pip bash
    - pip install docker-compose
    - touch ~/.gitignore
    - bin/docker-init.sh
    - cp app/config/parameters.gitlab-ci.yml app/config/parameters.yml
    - cp app/config/nodejs_parameters.yml.dist app/config/nodejs_paramteres.yml
    - chmod -R 777 app/cache app/logs var
    # Load only binary and mysql
    - docker-compose up -d binary mysql

build:
    stage: build
    script:
        - ${DOCKER_CMD} composer install -n
        - ${DOCKER_CMD} php app/console doctrine:database:create --env=test --if-not-exists
        - ${DOCKER_CMD} php app/console doctrine:migrations:migrate --env=test

codeSniffer:
    stage: test
    script:
        - ${DOCKER_CMD} bin/php-cs-fixer fix --dry-run --config-file=.php_cs

database:
    stage: test
    script:
        - ${DOCKER_CMD} php app/console doctrine:mapping:info --env=test
        - ${DOCKER_CMD} php app/console doctrine:schema:validate --env=test
        - ${DOCKER_CMD} php app/console doctrine:fixtures:load --env=test

unittest:
    stage: test
    script:
        - ${DOCKER_CMD} bin/phpunit -c app --debug

deploy_demo:
    stage: deploy
    script:
        - echo "Deploy to staging server"
    environment:
        name: staging
        url: https://staging.example.com
    only:
        - develop

deploy_prod:
    stage: deploy
    script:
        - echo "Deploy to production server"
    environment:
        name: production
        url: https://example.com
    when: manual
    only:
        - master

docker-compose.yml

version: "2"

services:
    web:
        image: nginx:latest
        ports:
            - "${HTTP_PORT}:80"
        depends_on:
            - mysql
            - elasticsearch
            - binary
        links:
            - binary:php
        volumes:
            - ".:/var/www"
            - "./app/config/docker/vhost.conf:/etc/nginx/conf.d/site.conf"
            - "${BASE_LOG_DIR}/nginx:/var/log/nginx"

    mysql:
        image: mysql:5.6
        environment:
            MYSQL_USER: test
            MYSQL_PASSWORD: test
            MYSQL_ROOT_PASSWORD: test
        ports:
            - "${MYSQL_PORT}:3306"
        volumes:
            - "${BASE_LOG_DIR}/mysql:/var/log/mysql"
            - "${BASE_MYSQL_DATA_DIR}:/var/lib/mysql"
            - "./app/config/docker/mysql.cnf:/etc/mysql/conf.d/mysql.cnf"

    elasticsearch:
        image: elasticsearch:1.7.6
        ports:
            - "${ELASTICSEARCH_PORT}:9200"
        volumes:
            - "${BASE_ELASTICSEARCH_DATA_DIR}:/usr/share/elasticsearch/data"

    binary:
        image: fchris82/kunstmaan-test
        container_name: bin
        volumes:
            - ".:/var/www"
            - "${BASE_LOG_DIR}/php:/var/log/php"
            - "~/.ssh:/home/user/.ssh"
        tty: true
        environment:
            LOCAL_USER_ID: ${LOCAL_USER_ID}

config.toml

[[runners]]
  name = "XXX Runner"
  url = "https://gitlab.xxx.xx/"
  token = "xxxxxxxxxxx"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "docker:latest"
    privileged = true
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    shm_size = 0
  [runners.cache]

1 个答案:

答案 0 :(得分:0)

好的,我发现了问题。我破坏了配置。如果您在spawn中使用 dind 服务,请不要在.gitlab-ci.yml文件中使用/var/run/docker.sock卷,反之亦然如果您使用“套接字”方法,请不要使用 dind 服务。

更多信息:https://docs.gitlab.com/ce/ci/docker/using_docker_build.html