title: gitlab-ci docker-in-docker access to insecure registry
body: <p>When configuring a gitlab-ci for building docker images and pushing them to my gitlab's insecure registry, I encountered several errors.  My gitlab-ci.yaml is laid out below:</p>
  
  <pre><code>stages:
    - build
    - deploy
  
  variables:
    GIT_SUBMODULE_STRATEGY: recursive
    CONTAINER_IMAGE: XXX:$CI_COMMIT_REF_NAME
  
  # The insecure-registry flag 
  services:
    - docker:dind
  
  build_container:
    image: docker:latest
    stage: build
    before_script:
      - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
  
    script:
      - docker build --pull -t $CONTAINER_IMAGE .
      - docker push $CONTAINER_IMAGE
  </code></pre>
  
  <p>The first error was:</p>
  
  <pre><code>  $ docker login -u gitlab-ci-token -p $CI_JOB_TOKEN myregistry.gitlab.com
    WARNING! Using --password via the CLI is insecure. Use --password-stdin.
    Warning: failed to get default registry endpoint from daemon (Cannot connect 
    to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon 
    running?). Using system default: https://index.docker.io/v1/
    Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the 
    docker daemon running?
  </code></pre>
  
  <p>This was resolved by updating the login command to </p>
  
  <pre><code>echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" myregistry.gitlab.com --password-stdin
  </code></pre>
  
  <p>Unfortunately after updating, I encountered another error:</p>
  
  <pre><code>$ echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" myregistry.gitlab.com --password-stdin
  Error response from daemon: Get https://myregistry.gitlab.com/v2/: dial tcp XX.XX.XXX.XXX:443: getsockopt: connection refused
  </code></pre>
  
  <p>How Can I resolve this?</p>