title: "gcloud auth activate-service-account" and "gcloud source repos clone" error
body: <p>I would like to use the following tools together:</p>
  
  <ul>
  <li><a href="https://www.docker.com/" rel="nofollow noreferrer">Docker</a></li>
  <li><a href="https://hub.docker.com/r/google/cloud-sdk/" rel="nofollow noreferrer">gcloud SDK</a></li>
  <li>gcloud Service Account</li>
  <li>gcloud Source Repo (as part of project dependencies)</li>
  </ul>
  
  <p>The steps i'm taking:</p>
  
  <p>1) Log into the Google Cloud Console at:
  <a href="https://console.cloud.google.com/iam-admin/serviceaccounts/project?project=project-name" rel="nofollow noreferrer">https://console.cloud.google.com/iam-admin/serviceaccounts/project?project=project-name</a></p>
  
  <p>2) Create a service account, for now give 'Owner' permissions, and download the json key as account-name.json</p>
  
  <p><a href="https://i.stack.imgur.com/ht8Wy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ht8Wy.png" alt="enter image description here"></a></p>
  
  <p>3) Add a Dockerfile:</p>
  
  <pre><code>FROM google/cloud-sdk
  COPY account-name.json /tmp/account-name.json
  RUN gcloud auth activate-service-account --key-file /tmp/account-name.json
  RUN rm /tmp/account-name.json
  RUN gcloud config set project project-name
  RUN gcloud config set account account-name@project-name.iam.gserviceaccount.com
  RUN gcloud source repos clone default --project=project-name
  </code></pre>
  
  <p>4) Build and run docker:</p>
  
  <pre><code>docker build  -t service-account-repo .
  docker run -ti service-account-repo
  </code></pre>
  
  <p>The error I get is:</p>
  
  <blockquote>
    <p>ERROR: (gcloud.source.repos.clone) You do not currently have an active
    account selected. Please run:</p>
    
    <p>$ gcloud auth login</p>
    
    <p>to obtain new credentials, or if you have already logged in with a
    different account:</p>
    
    <p>$ gcloud config set account ACCOUNT</p>
    
    <p>to select an already authenticated account to use.</p>
  </blockquote>
  
  <p>And no matter which commands I try, including setting the account and auth login, via docker exec it doesn't work.</p>
  
  <p>If I run the same commands locally it works, because I am already logged in with my main gcloud account.</p>
  
  <p>Do gcloud Service Accounts work with gcloud Source Repos? does anyone have a working example without their normal accounts logged in? Do I need to enable other cloud APIs to get it to work?</p>