<p>I followed this link - <a href="https://docs.docker.com/engine/api/sdk/examples/" rel="nofollow noreferrer">https://docs.docker.com/engine/api/sdk/examples/</a> and the docker SDK worked fine while I was using Docker containers. Now that I have moved to K8s, when I run the code I get error like &quot;Container Not Found&quot; . Is there a way to use Python Docker SDK inside of Kubernetes PODS?
Error:</p>
<pre><code>docker.errors.NotFound: 404 Client Error for http+docker://localhost/v1.41/containers/taskmanager-son/json: Not Found (&quot;No such container: taskmanager-son&quot;)
</code></pre>
<p>Note: I am not facing this error while running as Plain Docker Containers. This happens only when code runs inside of k8s PODS.</p>
<p>Note:
Also docker ps returns nothing since all containers are running inside K8s PODS</p>
<pre><code>import docker
docker_client = docker.from_env()
print(docker_client.containers.list())
# Returns none since since all containers are running inside K8s PODS
</code></pre>
<p>You can refer about Python Docker SDK here:
<a href="https://docker-py.readthedocs.io/en/stable/" rel="nofollow noreferrer">https://docker-py.readthedocs.io/en/stable/</a></p>

Arun Chandramouli
<p>You can't use the Docker API from inside Kubernetes; you need to use the <a href="https://kubernetes.io/docs/reference/using-api/" rel="nofollow noreferrer">Kubernetes API</a> instead.  You can do many of the same things you might have done with the Docker API using the Kubernetes API (launch new Jobs, query existing Pods, ...).  However, you can't build new images, the set of operations you perform can be limited by the Kubernetes RBAC system, and it is harder to take over the host.</p>
<p>The Docker API has some significant security considerations, and Kubernetes isn't guaranteed to be running Docker proper.  It's also worth noting that the Docker API could only inspect or operate on containers on the same node, where the Kubernetes API can see everything in the cluster.</p>
<p>(The differences between these two environments is a good reason to avoid needing direct access to either API, if you can avoid it.  For example, a job queue system like RabbitMQ plus a long-running worker can run in any environment, and is easier to both scale and control than launching a separate container per job.)</p>
