i don't Know if it exists a good practice to control a container from
another one, like run and stop a container.
It's a "good enough" practice, and plenty of people do this. CoreOS's /usr/bin/toolbox
is basically this, a few others like RancherOS do this as well.
If the only way is to use the rest api on the host have you got a good article which explains that ?
No, it is not. You can mount docker's socket into another docker container and then run docker commands on the host directly from inside the container. This practice is called "docker in docker", "dind", "nested containers" etc. There is a variation of this where people run full fledged versions of docker (docker engine/daemon + client) within an existing container, but that is not what you want to do here.
The gist of it is usually the same, the docker unix socket - /var/run/docker.sock
is exposed/mounted within the "controlling container" i.e the container you want to use to control the docker daemon. You then install the docker command line client and use docker commands as normal; docker ps
, docker start/stop/run
should all work as expected.
It's not trivial to set it up [1], and there are associated security concerns [2][3], but there are plenty of people doing it.
Here are your references:
[1] https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/ , See the section under Solution
, everything before that is what you should not be doing.
[2] https://www.lvh.io/posts/dont-expose-the-docker-socket-not-even-to-a-container.html
[3] https://raesene.github.io/blog/2016/03/06/The-Dangers-Of-Docker.sock/