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:

  • Bitbucket API version 1
  • exec not found using Dockerfile ENTRYPOINT
  • Setting up Text editor like Vim,Spacemacs to work with docker containers without installing tools on the host machine
  • How to pass host ip address to docker in mac OS?
  • Accessing a MySql database from external IP (Docker containers)
  • Connect to Docker Swarm for Continuous deploy
  • 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
    

  • Access a service from one container to other
  • How to check docker instance is running in Bash
  • The result of docker exec command
  • Environment variables for docker-compose inside of Jenkins
  • Docker Ubuntu image missing prompt, color and completion?
  • Kubernetes: how to debug CrashLoopBackOff
  • 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.