如何在构建时将环境变量设置为docker镜像名称

时间:2016-02-27 20:03:22

标签: bash command-line docker circleci

使用文件circle.yml文件构建docker镜像时,我试图传递一个环境变量$CIRCLE_PROJECT_USERNAME,以便该文件不是特定于项目的。不幸的是,使用标记参数-t构建的Docker失败了:

docker build -t CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH . returned exit code 1

repository name component must match "[a-z0-9]+(?:[._-][a-z0-9]+)*" Action failed: docker build -t CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH .

Circle.yml档案

machine:
  environment:
  services:
    - docker

dependencies:
  override:
    - docker info
    - docker build -t CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH .

test:
  override:
    - docker run -d $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH

deployment:
  hub:
    branch: master
    commands:
      - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASSWORD
      - docker push $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH

deployment:
  hub:
    branch: develop
    commands:
      - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASSWORD
      - docker push $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:$CIRCLE_BRANCH

1 个答案:

答案 0 :(得分:3)

应该工作,检查env是否实际设置并且只包含允许的字符:

[a-z0-9]+(?:[._-][a-z0-9]+)*

编辑:

docker build -t CIRCLE_PROJECT_USERNAME ...

也许只是错过$? ;)