Open In App

Which Are The Two Types Of Docker Clients ?

Last Updated : 16 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Differences between Docker CLI and Docker API

Parameter

Docker CLI

Docker API

Interface

Docker CLI is a command-line interface that allows users to interact with Docker directly.

Docker API is a REST API that allows for programmatic interaction with the Docker daemon.

Usage

Used primarily for managing individual containers.

Used to manage a wide range of Docker operations, including complex multi-container applications.

Execution

Commands are executed immediately and provide output directly to the user.

Docker API calls can be extended into scripts or applications for automated tasks.

Flexibility

Limited to the commands provided by Docker.

API can provides more flexibility and can be easily integrated with other tools.

Ease of Use

Makes simple things easy.

Makes complex things possible.

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.

On receiving the command to pull an docker image, the Docker daemon connects to the registry and pulls the image. Given that the image was not already cached in local. If that wasn’t the case, then Daemon directly loads the image from local.

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.

Running Docker CLI in Windows

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.

Creating and Building

# Creating an Image

$ docker build -t my-example-image

# Creating a container

$ docker create –name my-example-container ubuntu

Tagging and Registry Operations

# Tagging an Image

$ docker tag my-example-image:latest my-example-image:v1

# Pushing an Images to Registry

$ docker push my-registry/my-example-image:v1

# Pulling an Image from Registry

$ docker pull my-registry/my-example-image:v1

Starting and Running

# Starting a container

$ docker start my-example-container

# Running a containers from an Image

$ docker run -d –name my-container my-example-image:v1

Pausing and Resuming

# Pausing the container

$ docker pause my-example-container

# Unpausing the container

$ docker unpause my-example-container

Stopping and Restarting

# Stopping the container

$ docker stop my-example-container

# Restarting the container

$ docker restart my-example-container

Killing and Removing

# Killing the container

$ docker kill my-container

# Removing the container

$ docker rm my-container

# Removing unused Images

$ docker image rm my-custom-image:v1

Inspecting and Checking

# Inspecting an Image

$ docker image inspect my-custom-image:v1

# Checking Version

$ docker version

# Checking Info

$ docker info

Login and Logout

# Login

$ docker login

# Logout

$ docker logout

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.

Using the Docker Engine API it is possible to manage containers without having to use the Docker CLI. Using HTTP network calls similar functionality can be achived.

Checking the Docker API version on Windows

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.

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)

Types of Docker clients – FAQ’s

Can I use both CLI and Docker Desktop?

Yes. You can use both docker CLI and desktop application on the same machine. They both interact with the same Docker daemon.

Is Docker Desktop free?

Yes, Docker Desktop is free to use for individuals. Additionally, Docker provides Enterprise Edition which is paid.

Can I run Docker Desktop on Linux?

It is recomended to use CLI version on Linux. But, you can do follow these instructions.

Can I manage remote Docker hosts with Docker Desktop?

Yes. Docker Desktop can be configured to connect to remote Docker daemons.

What language is Docker written in?

Docker is build using the Go Language. But it is possible to create OCI compatible containers using other languages too.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads