Access Docker API from within container

Nowadays I’m contributing to pool project, which provides the simple http proxy launches docker container on access with commit-id of git repository, to be called even a “Just In Time Container”.

At first prototyping, pool provided the proxy service on vagrant VM. The proxy service kick-starts docker container by accessing Docker API, but it’s running on VM directly. So next I tried move the proxy service into docker container to separate it from docker host layer.

In this situation, How access docker api from within container? Finally I got this answer. It’s very simple solution(but may be dirty hack), that is sharing docker socket between container and host by running container with -v option.

For example, running container with -v option to share socket.

docker run -v /var/run/docker.sock:/var/run/dockerhost/docker.sock  --name inception -i -t centos /bin/bash`

Now, we can access docker api of host from within docker.
Yes, -H options enables to switch socket file.

bash-4.2# docker -H unix:///var/run/dockerhost/docker.sock ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
567a67857236        centos:latest       bin/bash            About a minute ago   Up About a minute                       inception
 
25
Kudos
 
25
Kudos

Now read this

Walter, a simple build pipeline tool

Today I announce Walter, a simple build pipeline tool with a collaborator @takahi_i. Beriefly, Walter is a tiny tool for executing build pipelines (such as automated build workflows) in Continuous Integration / Delivery(CI / CD).... Continue →