Docker撰写基于Gitlab CI – 管道错误

问题

我已经做了一个项目与码头撰写 。 它在本地主机上运行良好。 我想用这个基础来测试或分析代码与Gitlab亚军。 我解决了很多问题,如安装docker撰写,运行和构建选定的容器,并在容器中运行命令。 第一份工作成功了(!!!),但是之前的工作在“before_script”之前失败了:

在unix:///var/run/docker.sock中无法连接到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] 

好的,我发现了这个问题。 我宠坏了配置。 如果在.gitlab-ci.yml使用dind服务,那么不要在config.toml文件中使用/var/run/docker.sock卷,否则,如果使用“socket”方法,则不要使用dind服务。

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