How to execute Docker node command from container?

I want to write container management Docker script in Python. However, since I use CoreOS, Python is not part of the standard command. So, I am going to use the Pockon Docker container ( https://registry.hub.docker.com/_/python/ ) to execute my script. However, in this case, the script will be executed in the VM container, which does not have access to the Docker CLI host.

Is there a way to use Python (or other programming languages ​​not packaged in CoreOS) to control the host environment without installing it on the host machine?

PS, the script will do something like:

docker run/rm/stop <another container>;

+4
source share
3 answers

Docker HTTPS, Docker. HTTPS https://docs.docker.com/articles/https/

, ( ) Docker ,

docker -d --tlsverify --tlscacert=ca.pem \
--tlscert=server-cert.pem --tlskey=server-key.pem \
-H=0.0.0.0:2376

https://docs.docker.com/engine/reference/api/remote_api_client_libraries/

python docker-py , , docker-java, Java , .

+5

:

$ docker run -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock debian docker --version
Docker version 1.7.0, build 0baf609

, ( ).

Docker API . python.

+4

CoreOS python exec docker. , CoreOS python CoreOS, :

core@zz1 ~ $ toolbox python -c 'import os;os.system("/media/root/usr/bin/docker -H unix:///media/root/var/run/docker.sock ps")'
CONTAINER ID        IMAGE                                            COMMAND                CREATED             STATUS              PORTS               NAMES
2f5480ebc129        gcr.io/google_containers/etcd:2.0.12             "/usr/local/bin/etcd   47 minutes ago      Up 46 minutes                           k8s_etcd.3a160ccf_kube-dns-45.55.230.109_kube-system_790a48cfb2e2a5ae0abfcb6e3221275f_9d4fc659                   
ddbbc5e5033c        gcr.io/google_containers/skydns:2015-03-11-001   "/skydns -addr=0.0.0   47 minutes ago      Up 47 minutes                           k8s_skydns.db942972_kube-dns-45.55.230.109_kube-system_790a48cfb2e2a5ae0abfcb6e3221275f_59835376                 
...

-g

+2

Source: https://habr.com/ru/post/1599638/


All Articles