I have installed the Docker build step plugin for Jenkins.
The documentation is telling me:
Name : Choose a name for this Docker cloud provider Docker URL: The URL to use to access your Docker server API (e.g: http://172.16.42.43:4243)
How can I find my URL to the REST API (I have Docker installed on my host)?
The Docker Engine API is a RESTful API accessed by an HTTP client such as wget or curl , or the HTTP library which is part of most modern programming languages.
docker ps command shows the running container which displays the port your application is running. On browser type http://localhost:54529/your_application_page. if you are running application locally, then this is the port which needs to be changed in browser to access container application.
It is conventional to use port 2375 for un-encrypted, and port 2376 for encrypted communication with the daemon.
If you are on Linux and need to connect to Docker API on the local machine, its URL is probably unix:///var/run/docker.sock
, like it is mentioned in documentation: Develop with Docker Engine SDKs and API
By default the Docker daemon listens on
unix:///var/run/docker.sock
and the client must have root access to interact with the daemon. If a group named docker exists on your system, docker applies ownership of the socket to the group.
This might be helpful if you are connecting to Docker from a JetBrains IDE.
Here are two approaches.
How do I access the Docker REST API remotely?
Warning: After this setup your Docker REST API port (in this case
1111
) is exposed to remote access.
Here is how I enabled it on Ubuntu 16.04 (Xenial Xerus).
/lib/systemd/system/docker.service
as it will be replaced on upgrades)sudo systemctl edit docker.service
[Service] ExecStart= ExecStart=/usr/bin/docker daemon -H fd:// -H tcp://0.0.0.0:1111
For docker 18+, the content is a bit different:
[Service] ExecStart= ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:1111
Save the modified file. Here I used port 1111
, but any free port can be used.
Make sure the Docker service notices the modified configuration:
systemctl daemon-reload
sudo service docker restart
curl http://localhost:1111/version
{"Version":"17.05.0-ce","ApiVersion":"1.29","MinAPIVersion":"1.12","GitCommit":"89658be","GoVersion":"go1.7.5","Os":"linux","Arch":"amd64","KernelVersion":"4.15.0-20-generic","BuildTime":"2017-05-04T22:10:54.638119411+00:00"}
Now you can use the REST API.
How do I access the Docker REST API through a socket (from localhost)?
Connect the internal Unix socket somewhat like this,
Using curl
curl --unix-socket /var/run/docker.sock http:/localhost/version
And here is how to do it using PHP
$fs = fsockopen('/var/run/docker.sock'); fwrite($fs, "GET / HTTP/1.1\r\nHOST: http:/images/json\r\n\r\n"); while (!feof($fs)) { print fread($fs,256); }
In PHP 7 you can use curl_setopt with the CURLOPT_UNIX_SOCKET_PATH option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With