在docker-compose

时间:2018-01-15 12:06:26

标签: docker docker-compose

我的docker-compose中有以下内容。如何混合GITLAB_OMNIBUS_CONFIG和大写字母env变量。

version: '2.2'

services:
  redis:
    restart: always
    image: sameersbn/redis:latest
    command:
    - --loglevel warning
    volumes:
    - /srv/docker/gitlab/redis:/var/lib/redis:Z

  postgresql:
    restart: always
    image: sameersbn/postgresql:latest
    volumes:
    - /srv/docker/gitlab/postgresql:/var/lib/postgresql:Z
    environment:
    - DB_USER=gitlab
    - DB_PASS=password
    - DB_NAME=gitlabhq_production
    - DB_EXTENSION=pg_trgm

  gitlab:
    restart: always
    image: sameersbn/gitlab:10.3.3
    hostname: 'gitlab.example.com'
    depends_on:
    - redis
    - postgresql
    ports:
    - "30080:30080"
    - "30022:22"
    volumes:
    - /srv/docker/gitlab/gitlab:/home/git/data:Z
    environment:
        GITLAB_OMNIBUS_CONFIG: |
              external_url 'http://gitlab.example.com:30080'
              gitlab_rails['gitlab_shell_ssh_port'] = 30022
    - DEBUG=true
    - DB_ADAPTER=postgresql
    - DB_HOST=postgresql
    - DB_PORT=5432
    - DB_USER=gitlab
    - DB_PASS=password
    - DB_NAME=gitlabhq_production

    - REDIS_HOST=redis
    - REDIS_PORT=6379

    - TZ=Europe/Berlin
    - GITLAB_TIMEZONE=Berlin

我在第GITLAB_OMNIBUS_CONFIG行的上述配置中收到错误。

  

此处出现错误消息错误:yaml.parser.ParserError:解析时出错   块映射在" ./ docker-compose.yml",第24行,第5列预期   ,但发现' - ' in" ./ docker-compose.yml",第39行,   第5栏

我在这里关注一个例子。here

我的docker-compose版本

 docker-compose version
docker-compose version 1.18.0, build 8dd22a9
docker-py version: 2.6.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t  3 May 2016

感谢您的帮助。

1 个答案:

答案 0 :(得分:5)

问题出现了,因为所呈现的撰写文件混合了两种形式,用于为docker-compose指定environment variable

以下内容应该有效:

version: '2.2'

services:
  redis:
    restart: always
    image: sameersbn/redis:latest
    command:
    - --loglevel warning
    volumes:
    - /srv/docker/gitlab/redis:/var/lib/redis:Z

  postgresql:
    restart: always
    image: sameersbn/postgresql:latest
    volumes:
    - /srv/docker/gitlab/postgresql:/var/lib/postgresql:Z
    environment:
    - DB_USER=gitlab
    - DB_PASS=password
    - DB_NAME=gitlabhq_production
    - DB_EXTENSION=pg_trgm

  gitlab:
    restart: always
    image: sameersbn/gitlab:10.3.3
    hostname: 'gitlab.example.com'
    depends_on:
    - redis
    - postgresql
    ports:
    - "30080:30080"
    - "30022:22"
    volumes:
    - /srv/docker/gitlab/gitlab:/home/git/data:Z
    environment:
      GITLAB_OMNIBUS_CONFIG: |
              external_url 'http://gitlab.example.com:30080'
              gitlab_rails['gitlab_shell_ssh_port'] = 30022
      DEBUG: 'true'
      DB_ADAPTER: postgresql
      DB_HOST: postgresql
      DB_PORT: 5432
      DB_USER: gitlab
      DB_PASS: password
      DB_NAME: gitlabhq_production

      REDIS_HOST: redis
      REDIS_PORT: 6379

      TZ: Europe/Berlin
      GITLAB_TIMEZONE: Berlin