<p>Background:</p>

<p>I'm using Drone to test an application. Drone is deployed to Kubernetes, with with a <code>docker</code> (dind / docker-in-docker) container side-carred.</p>

<p>After the test completes, I use drone again to build &amp; push several docker images of about ~40mb each to us.gcr.io</p>

<p>When Drone creates the docker container to test my application, and the separate container to build my application and images, it creates a docker network to link the containers to build services, like a temporary test database (pretty standard in a CI pipeline).</p>

<p>However, the combination of Kubernetes pod networking, and Docker-in-Docker results in the following when trying to push to gcr:</p>

<pre><code>time="2018-03-19T03:31:12.037507241Z" level=error msg="Upload failed, retrying: net/http: HTTP/1.x transport connection broken: write tcp w.x.y.z:39662-&gt;z.y.x.w:443: write: broken pipe"
time="2018-03-19T03:31:17.208009069Z" level=error msg="Upload failed, retrying: net/http: HTTP/1.x transport connection broken: write tcp w.x.y.z:39662-&gt;z.y.x.w:443: write: broken pipe"
time="2018-03-19T03:31:17.216232506Z" level=error msg="Upload failed, retrying: net/http: HTTP/1.x transport connection broken: write tcp w.x.y.z:39662-&gt;z.y.x.w:443: write: broken pipe"
time="2018-03-19T03:31:17.407608372Z" level=error msg="Upload failed, retrying: net/http: HTTP/1.x transport connection broken: write tcp w.x.y.z:39662-&gt;z.y.x.w:443: write: broken pipe"
time="2018-03-19T03:31:17.410403394Z" level=error msg="Upload failed, retrying: net/http: HTTP/1.x transport connection broken: write tcp w.x.y.z:39662-&gt;z.y.x.w:443: write: broken pipe"
time="2018-03-19T03:31:23.432621075Z" level=error msg="Upload failed, retrying: unexpected EOF"
</code></pre>

<p>However, when pushing to (what I assume is) an older registry version, then it works perfectly.</p>

<p>When pushing to gcr while there is no docker container networking enabled, then it also works perfectly.</p>

<p>Here are the docker commands being ran. Obviously the sensitive data has been omitted.</p>

<pre><code>docker network create test-network &amp;&amp; \
docker run --network=test-network -d cockroachdb/cockroach:v1.1.2 -c /cockroach sql --insecure &amp;&amp; \
docker run --rm -it -e GKE_CLUSTER_NAME=my-cluster-1 -e GKE_CLUSTER_ZONE=us-east1-b -e GCP_PROJECT=my-gcp-project -e DOCKER_USE_GCP=true -v /var/run/docker.sock:/var/run/docker.sock --network=test-network us.gcr.io/my-project/runner /bin/sh -c 'mkdir -p src/git.example.com/project &amp;&amp; git clone https://user:pass!@git.example.com/project/project $GOPATH/src/git.example.com/project/project &amp;&amp; cd $GOPATH/src/git.example.com/project/project &amp;&amp; git checkout gcr &amp;&amp; jules -stage deploy_docker'
</code></pre>

<p>The <code>jules -stage deploy_docker</code> command runs a <code>go build</code>, <code>docker build</code>, and then <code>gcloud docker -- push...</code> on 8 different directories simultaneously.</p>

<p>So, summary:</p>

<p>Kubernetes pod + docker-in-docker + gcloud docker push results in a consistently interrupted connection.</p>

<p>Is there something I could do with docker daemon or kubernetes network settings or something to mitigate this? At the very least I want to understand why this is happening.</p>

<p>Thanks!</p>

<hr>

<p>Update:</p>

<p>This doesn't even require Kubernetes to happen!</p>

<p>I just tried it with a fresh GCE instance running Ubuntu and it happens there, too.</p>

<p>I contacted GCR support about this issue, as it seemed to only happen with GCR, and they informed me that the IAM account that was attempting to push to the registry was actually the default service account for GCE instances, and not the account that I provided to my Dockerfile.</p>

<p>However, that did not explain the "Broken pipe" and "EOF" errors when I should have been getting <code>401 - Unauthorized</code>.</p>

<p>I attempted the same push with the <code>google/cloud-sdk</code> docker image <a href="https://hub.docker.com/r/google/cloud-sdk/" rel="nofollow noreferrer">here</a> and it worked fine when I provided it the same key in a similar environment, so that told me that the way I installed gcloud on my docker image was bad.</p>

<p>Here's what I had:</p>

<pre><code>RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz
RUN tar -xvf google-cloud-sdk.tar.gz
RUN rm google-cloud-sdk.tar.gz
RUN google-cloud-sdk/install.sh --usage-reporting=false \
  --path-update=false \
  --bash-completion=false

ENV PATH="/go/google-cloud-sdk/bin:${PATH}"
RUN gcloud components install kubectl
RUN gcloud components install docker-credential-gcr
</code></pre>

<p>And here's what <code>google/cloud-sdk</code> had. Updating my Dockerfile to install it this way fixed my problem.</p>

<pre><code># Install gcloud
ENV CLOUD_SDK_VERSION 193.0.0

ARG INSTALL_COMPONENTS
RUN easy_install -U pip &amp;&amp; \
    pip install -U crcmod &amp;&amp; \
    export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" &amp;&amp; \
    echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" &gt; /etc/apt/sources.list.d/google-cloud-sdk.list &amp;&amp; \
    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - &amp;&amp; \
    apt-get update &amp;&amp; apt-get install -y google-cloud-sdk=${CLOUD_SDK_VERSION}-0 $INSTALL_COMPONENTS &amp;&amp; \
    gcloud config set core/disable_usage_reporting true &amp;&amp; \
    gcloud config set component_manager/disable_update_check true &amp;&amp; \
    gcloud config set metrics/environment github_docker_image &amp;&amp; \
    gcloud --version
</code></pre>

<p>I'm still clueless as to <em>why</em> this did it for me, so if anyone has any insight that'd be great.</p>
