Setup and Use Docker REST API
Install Docker
--------------
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubu... | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
sudo apt-get update
sudo apt-get install docker-ce
docker run hello-world
Setup Docker REST API
---------------------
edit /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H fd:// -H=tcp://0.0.0.0:5555
systemctl daemon-reload
sudo service docker restart
Test
----
Run API to:
see images
see running containers
start and stop containers
Sample commands:
-----------------------------------
docker run --name postgres -e POSTGRES_PASSWORD=password1 -d postgres
curl http://172.30.1.166:5555/images/json
curl http://172.30.1.166:5555/containers/json
curl --data "t=5" http://172.30.1.166:5555/containers/postgres/stop
curl --data "t=5" http://172.30.1.166:5555/containers/postgres/start