<p>I want to run a command on a docker container that has kubectl installed but not yet configured.</p>
<p>On my local machine, I have my kubectl authenticated and configured to communicate with a kubernetes cluster on Google Cloud.</p>
<p>If I run the command:</p>
<pre><code>docker run mycontainerimage kubectl get pods
</code></pre>
<p>I'll get the response:</p>
<pre><code>invalid configuration: no configuration has been provided
</code></pre>
<p>How can I pass my kubernetes credentials/configuration into the docker image running on my local machine? Thanks!</p>

aztrorisk
<p>You can <a href="https://docs.docker.com/engine/reference/commandline/run/#mount-volume--v---read-only" rel="nofollow noreferrer">mount</a> your config file with -v into the container</p>
<pre><code>docker run -v ~/.kube/config:/kube/config ...
</code></pre>
<p>and set the environment variable <a href="https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#the-kubeconfig-environment-variable" rel="nofollow noreferrer">KUBECONFIG</a></p>
<pre><code>docker run -v ~/.kube/config:/kube/config --env KUBECONFIG=/kube/config ...
</code></pre>
<p>now every kubectl call should use the mounted config file.</p>
