How to do it...

  1. Begin by creating a container from an alpine image, as shown here:

Here, we used the -d option of the curl command to pass our container configuration as a JSON data to the Docker engine. Evidently, the image is alpine, and the command we chose to run when the container starts is ls. In addition, we are also requesting the Docker engine to attach STDERR and STDOUT to this container, in order to retrieve the output of the ls command.

The HTTP header response code 201 Created indicates that our container is created successfully. Apparently, the response from the Docker engine is also a JSON payload. The ID field of the payload contains the container ID, which is f9fd4b2e2040d4dea32deb527889bf2fb95b351d8316a4c74bfb6e2e38c9b499. We shall use the short version of the container ID, f9fd4b2e2040, to perform further operations on this container.

  1. Since we want to capture the output of the ls command on the screen, let's attach to the container using the /attach API:

The /attach API would block the client (namely, curl) if it is called with the stderr, stdout, and stream parameter, so we are running the curl command in the background.

  1. Now, proceed to start the container using the /start API, as demonstrated here:

Cool, isn't it? We emulated the docker container run command with the Docker engine APIs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.159.197