Enabling & Developing With Docker Engine API

Enabling & Developing With Docker Engine API


Docker allows your applications to be shipped quickly to any platform running a Docker Engine, and run these applications in an isolated environment called a container.

Docker Engine is a client-server application, which provides three main components:

  1. A dockerd daemon process
  2. REST API which talks to the daemon
  3. Docker CLI


Docker Engine API is a RESTful API, accessible over HTTP, which can be used to develop automation scripts and Docker solutions. Docker Engine API is also available as SDKs for Go and Python programming language.

In this tutorial, you will enable the Docker Engine API and do some Docker operations, like, running a container, listing the logs of the container etc.


To follow the tutorial, you need to have:

  • Docker installed on a Linux system and managed by systemd


Step 1: Enabling the Docker Engine API

Start by creating a systemd unit file to override the default docker.service unit file.

1$ sudo systemctl edit --full docker.service

Provide dockerd daemon with an additional parameter to expose the API on port 4243

2ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://

Reload the systemd daemon to get the new unit file and restart the Docker service.

1$ sudo systemctl daemon-reload
2$ sudo systemctl restart docker.service

Step 2: Access the Docker Engine API

Check the version of Docker Engine installed on the system.

1$ curl localhost:4243/v1.41/version
 3    "Platform": {
 4        "Name": "Docker Engine - Community"
 5    },
 6    "Components": [
 7        {
 8            "Name": "Engine",
 9            "Version": "20.10.2",
10    [...]

Now our Docker Engine API is enabled to listen to HTTP requests. HTTP clients curl or wget can be used to interact with the API.

Step 3: Running A Container

First, pull the alpine image.

1$ curl -X POST "http://localhost:4243/v1.41/images/create?fromImage=alpine:latest"
1# Output truncated
2{"status":"Pulling from library/alpine","id":"latest"}
4{"status":"Status: Downloaded newer image for alpine:latest"}

Create the container and grab the container Id. It will be used for the rest of the REST calls.

1curl -H "Content-Type: application/json" \
2  -d '{"Image": "alpine:latest", "Cmd": ["echo", "hello world"]}' \
3  -X POST http://localhost:4243/v1.41/containers/create

Start the container

1curl -X POST http://localhost:4243/v1.41/containers/d4ac7504007/start

See the logs to verify the echo statement printed hello world on the stdout.

1curl -o - "http://localhost:4243/v1.41/containers/d4ac7504007/logs?stdout=1"
1hello world

Remove the container

1curl -X DELETE "http://localhost:4243/v1.41/containers/d4ac7504007"


Learned how Docker Engine API can be accessed using HTTP clients by providing the additional parameters to the dockerd command in the systemd docker.service unit file. Also created a container which runs the latest alpine image and prints hello world on the standard output.