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:

  • Callback (or equivalent) when container w/ Rails app finishes booting?
  • How to answer command line prompts in script in docker
  • Ubuntu run service in foreground
  • how to continue a bash script after it reboots the machine from the command after the reboot command?
  • Docker network does not work with bash entrypoint
  • automatic docker login within a bash script
  • 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
    

  • Trying to run Cloudera Image in Docker
  • Connect to Docker Swarm for Continuous deploy
  • IBM/secure-gateway-client docker run with the --F (acl file) option
  • Docker beta for Windows and Windows Bash: path must be absolute
  • How can I remove all containers by image name and do nothing if it already removed
  • Cannot find the enviromental parameter
  • 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.