title: How to generate admin.conf file for kubectl in Docker container
body: <p>I am working on running a project locally inside a Docker container with Linux-amd64 architecture. The start script runs the following command</p>
  <pre><code>kubectl create configmap -o yaml \
      --dry-run=true \
      --from-file ./configs/local/grafana \
      grafana-dashboards-source-config |
      kubectl apply -f -
  </code></pre>
  <p>which runs well on my MacOs but when run inside the Docker container, it fails with <code>The connection to the server localhost:8080 was refused - did you specify the right host or port?</code> error. On browsing resources online, many posts suggested to use these commands to fix the issue</p>
  <pre><code>  mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config
  </code></pre>
  <p>but inside my Docker container I cannot find the <code>/kubernetes</code> directory and hence the <code>admin.conf</code> file.
  I am using <code>COPY --from=lachlanevenson/k8s-kubectl:v1.10.3 /usr/local/bin/kubectl /usr/local/bin/kubectl</code> command in my Dockerfile to install kubectl and <code>kubectl version --client</code> returns with</p>
  <pre><code>Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;10&quot;, GitVersion:&quot;v1.10.3&quot;, GitCommit:&quot;2bba0127d85d5a46ab4b778548be28623b32d0b0&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2018-05-21T09:17:39Z&quot;, GoVersion:&quot;go1.9.3&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
  </code></pre>
  <p>I wished to know what is the correct way to install kubectl while creating a Docker image so that I can find the <code>kubernetes/admin.conf</code> file, or if there is a way to generate it after kubectl is installed?</p>