Working with Docker API
Along with API, docker provides native SDKs in Go and Python. These allow to build and scale docker applications. The Docker API reference docs can be found here.
Here we’ll be using python to create, manage and destory containers. Before we get started, you need to have the docker package installed on the machine. You can easily do this by running pip install docker, keep the docker running.
# PYTHON CODE
# make sure docker package is installed
# by running the below command
# pip install docker
import docker
client = docker.from_env()
# runs echo command on ubuntu contianer
print(client.containers.run(“ubuntu”, [“echo”, “hello geeks!”]))
# lists all the running containers
for container in client.containers.list():
print(container.id)
# stops all the running containers
for container in client.containers.list():
container.stop()
# lists all the images
for image in client.images.list():
print(image.id)
Which Are The Two Types Of Docker Clients ?
Docker is an open-source containerization platform. It has made deployments easy by packaging applications and their dependencies into lightweight containers. The Docker client is the primary interface through which users interact with the Docker system.
There are two types of Docker clients. Command Line and Graphical. In this article, we’ll be exploring these and understanding each of their roles.