Building images using APIs
In the previous recipe, we explored a few actions on Docker images using APIs. In this recipe, we will build a Docker image using the /build
API. Here is the /build
API snippet from Swagger Editor:

How to do it...
- Begin by cloning the https://github.com/docker-cookbook/apache2 repository, as follows:
$ git clone https://github.com/docker-cookbook/apache2
This repository contains the Dockerfile
to bundle an apache2
service; listed here is the content of the Dockerfile
:

- Let's create the build context by bundling the content of the cloned
apache2
repository as a tar file, as demonstrated here:
$ cd apache2$ tar cvf /tmp/apache2.tar *
- Continue on to build the Docker image using the
/build
API:
$ curl -X POST \ -H "Content-Type:application/tar" \ --data-binary '@/tmp/apache2.tar' \ --unix-socket /var/run/docker.sock \ http:/build
While the build is in progress, you will receive the build logs as a series of JSON messages. Once the build is successfully...