Launching containers using APIs
In Chapter 2, Working with Docker Containers, recipe Starting a container, we methodically and meticulously explored different ways of running containers. In all those scenarios, we used the docker container run
command with a few options, and all our containers were up and running. However, behind the scenes, the Docker CLI makes it possible by first creating the container layer through the /create
API and then launches the application (cmd
) through the /start
API, as visualized here:

In addition to the /create
and /start
API, the Docker CLI uses APIs such as /attach
and /wait
to fulfill our request. In this recipe, we will create an alpine
container and run a simple ls
command to demonstrate the steps involved in launching a container through the Docker engine APIs.
How to do it...
- 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...