How to set environment variable as docker image name on build

When using the file circle.yml file to build a docker image I’m trying to pass an environment variable $CIRCLE_PROJECT_USERNAME so that the file is less project specific. Unfortunately Docker build with the tag argument -t fails with:

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 file:

  • docker - cannot find aws credentials in container although they exist
  • Make docker container run forever while being able to gracefully stop
  • Why docker exec is killing nohup process on exit?
  • What's causing authentication error when pushing Docker image to Google Container Registry?
  • Running a Bash Script from (on Docker Container B) from Docker Container A
  • “bash: fork: retry: No child processes ” when running docker quick start terminal or in /git bash shell
  • 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
    

  • How to run linux command before starting up git bash terminal
  • Docker bash prompt not display color
  • docker neo4j cannot connect to load csv from remote url
  • Cannot return to shell session after script
  • ERROR 1582 (42000) Incorrect parameter count in the call to native function 'FROM_UNIXTIME'
  • “tput: No value for $TERM and no -T specified ” error on docker [on hold]
  • One Solution collect form web for “How to set environment variable as docker image name on build”

    Should work, check if the env are actually set and only contain allowed characters:

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

    Edit:

    docker build -t CIRCLE_PROJECT_USERNAME ...
    

    Maybe just missing a $ here? 😉

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.