title: Docker push to Google Cloud Registry -- HTTP request to an HTTPS server
body: <p>I can't seem to get my <code>.gitlab-ci.yml</code> pipeline working properly. I'm able to build, test, and re-tag on gitlab just fine, but deploy stage fails on trying to push an image to gcr.io. The relevant excerpts from the pipeline file and the fail message are below. I've tried slim and alpine images, and confirmed via echo, export, and <code>gcloud auth list</code> that the GCP_SERVICE_ACCOUNT variable is that which I set in the gitlab system and successfully authenticated. I can't find anything via googling that addresses the misalignment of http vs https -- only syntax consistent with what I've done, or for alternate authentication methods. In the past when I've authenticated on my local machine and pushed to gcr.io, <code>gcloud push ...</code> worked just fine.</p>
  <p>I also tried inserting <code>docker-credential-gcr configure-docker --token-source=&quot;gcloud&quot;</code> and using asia.gcr.io (as I'm in AUS) per answers at <a href="https://stackoverflow.com/questions/46960446/push-to-google-container-registry-fails-retrying">Push to google container registry fails: Retrying</a>. The problem in that post isn't the same, but I'm flailing at this point.</p>
  <p>What am I getting wrong, please?</p>
  <pre><code>image: docker:19.03.12
  
  services:
    - docker:19.03.12-dind
  
  stages:
    - build
    - test
    - release
    - deploy
  
  variables:
    GIT_DEPTH: 1
    DOCKER_HOST: tcp://docker:2376
    DOCKER_TLS_CERTDIR: &quot;/certs&quot;
    CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
    CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
    GCR_IO_IMAGE: gcr.io/proj-000000/$CI_REGISTRY_IMAGE:latest
  
  ...
  
  deploy:
    image: google/cloud-sdk:slim
    stage: deploy
    only:
    - master
    before_script:
    - echo $GCP_SERVICE_ACCOUNT &gt; /tmp/service_account.json
    - gcloud auth activate-service-account --key-file /tmp/service_account.json
    script:
    - docker push $GCR_IO_IMAGE
    - gcloud app deploy app.yaml --project proj --image-url $GCR_IO_IMAGE
  </code></pre>
  <blockquote>
  <p>$ docker push $GCR_IO_IMAGE
  Error response from daemon: Client sent an HTTP request to an HTTPS server.
  ERROR: Job failed: exit code 1</p>
  </blockquote>
  <p><strong>Update</strong> following Frederic G's post below:
  The <code>gcloud docker ...</code> approach appears to be deprecated now, but following the suggestion that pops up in the fail notes:</p>
  <pre><code>deploy:
    image: google/cloud-sdk:alpine
    stage: deploy
    only:
    - master
    script:
    - gcloud auth activate-service-account --key-file /tmp/service_account.json
    - gcloud auth configure-docker
    - docker push $GCR_IO_IMAGE
    - gcloud app deploy sandkastenapp.yaml --project sandkasten --image-url $GCR_IO_IMAGE
  </code></pre>
  <p>now gives:</p>
  <pre><code>$ gcloud auth configure-docker
  Adding credentials for all GCR repositories.
  WARNING: A long list of credential helpers may cause delays running 'docker build'. We recommend passing the registry name to configure only the registry you are using.
  After update, the following will be written to your Docker config file
   located at [/root/.docker/config.json]:
   {
    &quot;credHelpers&quot;: {
      &quot;gcr.io&quot;: &quot;gcloud&quot;,
      &quot;us.gcr.io&quot;: &quot;gcloud&quot;,
      &quot;eu.gcr.io&quot;: &quot;gcloud&quot;,
      &quot;asia.gcr.io&quot;: &quot;gcloud&quot;,
      &quot;staging-k8s.gcr.io&quot;: &quot;gcloud&quot;,
      &quot;marketplace.gcr.io&quot;: &quot;gcloud&quot;
    }
  }
  Do you want to continue (Y/n)?  
  Docker configuration file updated.
  $ docker push $GCR_IO_IMAGE
  read tcp 172.17.0.4:42954-&gt;172.17.0.3:2376: read: connection reset by peer
  ERROR: Job failed: exit code 1
  </code></pre>