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:

  • Saving function output into a variable named in an argument
  • Access container environment variables in inline run command
  • Permission error when deploying Docker app from CI server to Heroku
  • Using variable interpolation in string in Docker
  • Missing Carriage Return in Docker for Mac Containers
  • Using SUID in Alpine Docker Image
  • 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
    

  • Creating bash script from Dockerfile strips comments
  • Unable to modify file as part of entry point command
  • Generating -bind parameter in Consul JSON files for use with Marathon
  • Node Docker Container - Pulls from Git Repo for Node App Source Upon Running
  • Difference between sh and bash
  • Jenkins - Cannot run program “docker”
  • 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.