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.

Similar Reads

Differences between Docker CLI and Docker API

...

Uses of a Docker client

Before we dig deep into each particular client, let us first briefly look into why we need a Docker client in the first place and try to understand its place in the Docker ecosystem....

Docker client interacts with Docker daemon

Docker uses a Client Server Architecture. What that means is that the Docker client passes the commands to the Docker daemon to execute. This connection is made by a REST API....

Easy Management of Images & Containers

Docker client make it easy to create, manage, and delete docker resource. These primiarly include images and containers. The Docker client provides simple and easy to use commands that can be run to provision the required resource or run the required operations....

Monitoring and Allocating Resources

Docker client provides a high level overview of the resource utilization of the Host Operating System on which the docker is actually running. It interacts with the daemon to manage and limit the CPU, memory, network usage across different containers....

Types of Docker clients

Docker Command-Line Interface (CLI) Docker API (Application Programming Interface)...

Docker Command-Line Interface (CLI)

Docker CLI is a powerful command-line tool that allows for efficent management of Docker resources. Using the Docker CLI, commands can be run directly from the terminal achiveing making it faster....

Advantages of Docker CLI

The Docker CLI is minimalistic in nature and doesn’t consume significant resources. It can be configured to automate tasks using shell scripts or other automation tools. It is a faster way of interacting with docker...

Disadvantages of Docker CLI

It might not be intutive for begginers Commands need to be memorized or looked up each time....

Using Docker CLI

Docker provides various commands making making the lifecycle management of images and containers seamless, here we’ll look into a few of the most frequently used commands....

Docker API (Application Programming Interface)

Docker provides a REST API. Using this API docker client interacts with Docker daemon. It is also refered as Docker Engine API. This API can be accessed by an HTTP client, such as wget or curl. This API can also be used with any programming language that provides a HTTP library....

Advantages of Docker API

Docker API enables cross-platform consistency and allows for automating tasks. Docker provides a stable environment for testing, development and production. This environment is also space and resource efficient. Docker API is backwards compatible, allowing to use different versions of the API....

Disadvantages of Docker API

Working directly with an API, brings a learning curve for beginner programmers. If not properly managed, it can introduce security vulnerabilities. Managing a large number of containers can become complex and provides limited orchestration capabilities....

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....

Types of Docker clients – FAQ’s

Can I use both CLI and Docker Desktop?...