<p>My local system's kubectl is currently pointing to my digitalocean kubernetes cluster.
I wrote an app in Rust that can list the pods on my cluster and their CPU usage, which is working fine on local system.</p>
<p>Now, I dockerized this application, so now it is running as a container.</p>
<p>How can I configure my docker-compose in such a way, so that it can access local system's kubectl ?</p>
<hr />
<p>I tried this on the basis of suggested solutions:</p>
<pre><code>version: &quot;3.3&quot;

services:
  custom-tool:
    container_name: custom-tool
    image: myimage:v16
    restart: always
    command: ./main-thread
    environment:
      - KUBECONFIG=/root/config
    volumes:
      - /home/keval/.kube/config:/root/config
</code></pre>
<p>But, no luck yet !</p>

Keval Bhogayata
<p>It seems like you can create your own configuration programmatically, have it read from <code>~/.kube/config</code> or from env variables: <a href="https://docs.rs/kube/0.73.0/kube/struct.Config.html" rel="nofollow noreferrer">https://docs.rs/kube/0.73.0/kube/struct.Config.html</a></p>
<p>The easiest option you have is to have your local <code>.kube/config</code> available inside your container by using a <a href="https://stackoverflow.com/a/54658017/19059974">bind mount</a> (most likely at <code>/root/.kube/config</code>).</p>
<p>It will look like this:</p>
<pre><code>version: &quot;3.3&quot;

services:
  custom-tool:
    container_name: custom-tool
    image: myimage:v16
    restart: always
    command: ./main-thread
    volumes:
      - type: bind
        source: /home/keval/.kube/config
        target: /root/.kube/config
</code></pre>
