【问题标题】:docker-compose throws error with gitlab-cidocker-compose 使用 gitlab-ci 引发错误
【发布时间】:2018-03-20 11:36:08
【问题描述】:

我尝试将 Gitlab CIdocker-compose 一起使用,但我总是收到此错误:

$ docker-compose up -d --build
Creating network "backoffice_default" with the default driver
Building php
Creating backoffice_database_1 ... 
Creating backoffice_database_1 ... done
Creating backoffice_php_1 ... 
Creating backoffice_php_1 ... done

$ docker-compose exec php composer -v
Traceback (most recent call last):
  File "bin/docker-compose", line 6, in <module>
  File "compose/cli/main.py", line 68, in main
  File "compose/cli/main.py", line 121, in perform_command
  File "compose/cli/main.py", line 464, in exec_command
  File "site-packages/dockerpty/pty.py", line 338, in start
  File "site-packages/dockerpty/io.py", line 32, in set_blocking
ValueError: file descriptor cannot be a negative integer (-1)
Failed to execute script docker-compose

我使用 docker 和 shell runner,如下:

[[runners]]
  name = "direct runner"
  url = MY_GITLAB_URL
  token = REPO_GITLAB_TOKEN
  executor = "shell"
  [runners.cache]

这是我的docker-compose.yml 文件:

version: '2'

services:

  database:
    image: mysql:latest
    environment:
      MYSQL_DATABASE: database
      MYSQL_ROOT_PASSWORD: mysql_strong_password
      MYSQL_USER: database
      MYSQL_PASSWORD: mysql_strong_password

  php:
    build: ./app/docker
    tty: true
    volumes:
      - ./app/docker/php.ini:/usr/local/etc/php/conf.d/custom.ini
      - ./:/var/www/symfony
    links:
      - database

这是我的.gitlab-ci.yml

stages:
- build
- cleanup_build
- test
- deploy
- cleanup

before_script:
- docker info

build:
  stage: build
  script:
  - docker-compose up -d --build
  - docker-compose exec php composer -v
  - docker-compose exec php composer install
  - docker-compose exec php php bin/console doctrine:schema:create --dump-sql --force
  - docker-compose exec php php bin/console doctrine:fixtures:load -n

cleanup_build:
  stage: cleanup_build
  script:
  - docker-compose config
  - docker-compose ps
  - docker-compose logs php
  - docker-compose logs database
  - exit 1
  when: on_failure

phpunit:
  stage: test
  script:
  - docker-compose exec -T php phpunit -c .

deploy:
  stage: deploy
  script:
  - echo "deploy to staging server"

cleanup:
  stage: cleanup
  script:
  - docker-compose down

你们知道如何解决这个问题吗? 因为我使用gitlab-runner 用户直接从shell 尝试并执行相同的cmd,所以我没有任何错误。我尝试使用-T 标志运行docker-compose exec,但出现另一个错误:ERROR: Job failed: exit status 1 没有附加消息

【问题讨论】:

    标签: docker-compose gitlab


    【解决方案1】:

    This question 帮助我找到解决该问题的方法。

    只需在 exec 之后添加一个 -T arg 就会有很大帮助

    【讨论】:

      猜你喜欢
      • 2020-02-02
      • 2017-07-06
      • 1970-01-01
      • 2021-08-29
      • 2016-06-24
      • 1970-01-01
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      相关资源
      最近更新 更多