title: BitBucket pipelines - docker unauthorized: authentication required - Docker push with successful login
body: <p>This issue applies to Bitbucket pipelines. I have seen the other related questions, and frankly the Bitbucket yaml and Dockerfile scripts work great when directly executed in bash terminal. </p>
  
  <p>Just when executing the pipeline, it fails, right after successful login. </p>
  
  <p>Here is my Yaml file:</p>
  
  <pre><code># enable Docker for the repository
  options:
    docker: true
  
  # Start the pipeline
  pipelines:
    default:
      - step:
          script: # Name the image and create a docker image
            - docker build -t "my_docker_id/my_app:latest" . 
            - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
            - docker push my_docker_id/my_app:latest
  </code></pre>
  
  <p>And my Dockerfile looks like:</p>
  
  <pre><code>FROM ubuntu:latest
  
  # Install Python and related tools
  RUN apt-get update &amp;&amp; apt-get install -y --no-install-recommends apt-utils
  RUN apt-get -y upgrade
  RUN apt-get install -y python3
  RUN apt-get install -y python3-pip
  RUN pip3 install --upgrade pip
  
  # Now use Pip to install Flask
  RUN pip3 install flask
  
  # Set the working directory to Ubuntu user home
  WORKDIR /home/ubuntu
  
  # Then copy the website folder to home folder
  COPY . /home/ubuntu
  </code></pre>
  
  <p>The docker login succeeds:</p>
  
  <pre><code>docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD&lt;1s
  Login Succeeded
  </code></pre>
  
  <p>The pipeline fails on:</p>
  
  <pre><code>docker push my_docker_id/my_app:latest
  </code></pre>
  
  <p>Fails with:</p>
  
  <p><code>+ docker push cbrodock/corpsite:latest
  The push refers to a repository [docker.io/cbrodock/corpsite]
  bdca855fbe4a: Preparing
  d147d767df7b: Preparing
  f6aad432f761: Preparing
  0da658ad5264: Preparing
  84e11e4ededf: Preparing
  50fd25888dad: Preparing
  2cb0a11f65e0: Preparing
  ad8ba289abb4: Preparing
  33f1a94ed7fc: Preparing
  b27287a6dbce: Preparing
  47c2386f248c: Preparing
  2be95f0d8a0c: Preparing
  2df9b8def18a: Preparing
  50fd25888dad: Waiting
  47c2386f248c: Waiting
  2cb0a11f65e0: Waiting
  33f1a94ed7fc: Waiting
  2df9b8def18a: Waiting
  b27287a6dbce: Waiting
  2be95f0d8a0c: Waiting
  ad8ba289abb4: Waiting
  unauthorized: authentication required
  </code></p>
  
  <p>If I execute the same exact steps in my bash terminal on MacOS, they execute fine and push succeeds. </p>
  
  <p>Any ideas?</p>