{"id":459204,"date":"2022-06-07T22:59:25","date_gmt":"2022-06-07T19:59:25","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-get-started-using-the-docker-engine-api\/"},"modified":"2022-06-07T22:59:25","modified_gmt":"2022-06-07T19:59:25","slug":"how-to-get-started-using-the-docker-engine-api","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/","title":{"rendered":"#How to Get Started Using the Docker Engine API"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a3c564d9ae74\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a3c564d9ae74\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#%E2%80%9CHow_to_Get_Started_Using_the_Docker_Engine_API%E2%80%9D\" >&#8220;How to Get Started Using the Docker Engine API&#8221;<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#Enabling_Docker_Engines_API\" >Enabling Docker Engine\u2019s API<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#A_Note_On_Security\" >A Note On Security<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#Using_the_API\" >Using the API<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#Common_Endpoints\" >Common Endpoints<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#Listing_Containers\" >Listing Containers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#Starting_a_New_Container\" >Starting a New Container<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#Cleaning_Up_Containers\" >Cleaning Up Containers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#Listing_Images\" >Listing Images<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#Building_Images\" >Building Images<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#Listing_Daemon_Event_Logs\" >Listing Daemon Event Logs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#Getting_System_Information\" >Getting System Information<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-using-the-docker-engine-api\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E2%80%9CHow_to_Get_Started_Using_the_Docker_Engine_API%E2%80%9D\"><\/span>&#8220;How to Get Started Using the Docker Engine API&#8221;<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<div>\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage aligncenter size-full wp-image-14169\" data-pagespeed-lazy-srcset=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/csit\/2021\/09\/993634a1.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.howtogeek.com\/wp-content\/uploads\/csit\/2021\/09\/993634a1.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/csit\/2021\/09\/993634a1.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1200\" height=\"675\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Docker Engine exposes a REST API which you can use to control your containers without the <code>docker<\/code> CLI. The API exposes equivalent functionality using HTTP network calls. You can <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">script<\/a> common Docker operations using your favorite programming language or remotely control one of your hosts. The CLI internally relies on the same API to provide its built-in commands.<\/p>\n<p>In this article we\u2019ll look at the basics of enabling and using the API. If you\u2019ve got a specific use case in mind, refer to the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/engine\/api\/v1.41\">API reference documentation<\/a> to identify the endpoints you need.<\/p>\n<h2 id=\"enabling-docker-engines-api\"><span class=\"ez-toc-section\" id=\"Enabling_Docker_Engines_API\"><\/span>Enabling Docker Engine\u2019s API<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The API is integrated with Docker Engine. Any functioning Docker host is already primed to cater for API interactions. To expose the service, you need to bind the Docker daemon to a TCP socket as well as, or instead of, the default Unix socket. Start <code>dockerd<\/code> with the <code>-H<\/code> flag to specify the sockets to listen on:<\/p>\n<pre>sudo dockerd -H unix:\/\/\/var\/run\/docker.sock -H tcp:\/\/0.0.0.0:2375<\/pre>\n<p>This command exposes the API on port 2375. The default Unix socket is retained so the Docker CLI will continue functioning without any reconfiguration. Port 2375 is used for Docker by convention; feel free to change it to suit your environment.<\/p>\n<p>You can make Docker always start with these settings by editing its <code>systemd<\/code> service configuration file. Edit or create <code>\/etc\/systemd\/system\/docker.service.d\/options.conf<\/code>, find the <code>ExecStart<\/code> line, and modify it to include your extra flags:<\/p>\n<pre>[Service]&#13;\nExecStart=\/usr\/bin\/dockerd -H unix:\/\/\/var\/run\/docker.sock -H tcp:\/\/0.0.0.0:2375<\/pre>\n<p>Reload your <code>systemd<\/code> configuration to apply the change:<\/p>\n<pre>sudo systemctl daemon-reload<\/pre>\n<p>Now you\u2019re ready to interact with the Docker Engine API on <code>127.0.0.1:2375<\/code>.<\/p>\n<h2 id=\"a-note-on-security\"><span class=\"ez-toc-section\" id=\"A_Note_On_Security\"><\/span>A Note On Security<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The steps above expose the API with no protection whatsoever. Anyone with access to port 2375 on your host can send arbitrary commands to the Docker daemon, starting new containers, filling your disk with images, or destroying existing workloads.<\/p>\n<p>You should set your firewall to block connections to the port unless you\u2019re intentionally exposing Docker on your network. If you do want to enable remote access, you should configure TLS for the daemon socket to limit access to authenticated clients.<\/p>\n<p>When TLS is enabled you\u2019ll need to install your daemon\u2019s certificate authority on each of your clients. You\u2019ll have to supply the client certificate and client key with each request you make. The steps to take will depend on the tool you\u2019re using. Here\u2019s an example for <code>curl<\/code>:<\/p>\n<pre>curl https:\/\/127.0.0.1:2375\/v1.41\/containers\/json --cert client-cert.pem --key client-key.pem<\/pre>\n<p>You might not need to bind a TCP socket at all depending on your use case. If your client supports Unix sockets, you could use Docker\u2019s existing one to make your connections:<\/p>\n<pre>curl --unix-socket \/var\/run\/docker.sock http:\/\/localhost\/v1.41\/containers<\/pre>\n<p>This can be a safer choice than risking unintentional exposure of a TCP socket.<\/p>\n<h2 id=\"using-the-api\"><span class=\"ez-toc-section\" id=\"Using_the_API\"><\/span>Using the API<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/engine\/api\/v1.41\/#section\/Versioning\">API uses<\/a> versioned endpoints so you can pin to specific versions of request and response formats. You must indicate the version you\u2019re using at the start of each endpoint URL. v1.41 is the latest release present in production Docker builds at the time of writing.<\/p>\n<pre>http:\/\/127.0.0.1:2375\/v1.41<\/pre>\n<p>API endpoints are grouped into REST functional units. These map to Docker\u2019s fundamental object types such as containers, images, and volumes. You can usually find the APIs for a specific object type within the base URL that starts with its name:<\/p>\n<pre># APIs related to container operations&#13;\nhttp:\/\/127.0.0.1:2375\/v1.41\/containers<\/pre>\n<p>The API uses JSON for all data exchanges with your HTTP client. Endpoints accept JSON request bodies and issue JSON responses in return. This should simplify data handling inside your applications as you can use the JSON library included with your programming environment. Tools like <code>jq<\/code> can be used to condense, filter, and sort responses if you\u2019re experimenting in your terminal.<\/p>\n<h2 id=\"common-endpoints\"><span class=\"ez-toc-section\" id=\"Common_Endpoints\"><\/span>Common Endpoints<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>As the API replicates the functionality of Docker\u2019s CLI, there\u2019s too many possible endpoints to cover them all here. Instead we\u2019ll demonstrate a few of the most commonly used options relating to Docker\u2019s core functionality.<\/p>\n<h3 id=\"listing-containers\"><span class=\"ez-toc-section\" id=\"Listing_Containers\"><\/span>Listing Containers<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The complete list of containers on the host can be obtained from the <code>\/containers\/json<\/code> endpoint:<\/p>\n<pre>curl http:\/\/127.0.0.1:2375\/v1.41\/containers\/json<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15747\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/csit\/2022\/02\/7c29cc8e.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1279\" height=\"710\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>It defaults to surfacing only running containers. Add <code>all=true<\/code> to the query string to include stopped containers too. Limit the total number of containers returned with the <code>limit<\/code> parameter, such as <code>limit=10<\/code>. Only the 10 most recently-created containers will be included.<\/p>\n<p>Several <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/engine\/api\/v1.41\/#tag\/Container\">different filters<\/a> are available to prune the list to containers with particular attributes. These are set with the following syntax:<\/p>\n<pre>curl http:\/\/127.0.0.1:2375\/v1.41\/containers\/json?filters={\"name\":\"demo\"}<\/pre>\n<p>This URL returns the information associated with the <code>demo<\/code> container. Other filters can be expressed in a similar way such as <code>{\"status\":[\"running\",\"paused\"]}<\/code> to get running and paused containers or <code>{\"health=[\"healthy\"]}<\/code> for only healthy containers.<\/p>\n<h3 id=\"starting-a-new-container\"><span class=\"ez-toc-section\" id=\"Starting_a_New_Container\"><\/span>Starting a New Container<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Starting a container is a two-stage process when using the API. First you need to create the container, then start it in a separate API call.<\/p>\n<p>Create your container by making a <code>POST<\/code> request to the <code>\/containers\/create<\/code> endpoint. This needs a JSON body with fields that correspond to the flags accepted by the <code>docker run<\/code> CLI command.<\/p>\n<p>Here\u2019s a minimal example of creating a container:<\/p>\n<pre>curl http:\/\/127.0.0.1:2375\/v1.41\/containers\/create &#13;\n    -X POST &#13;\n    -H \"Content-Type: application\/json\" &#13;\n    -d '{\"Image\": \"example-image:latest\"}'<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15748\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/csit\/2022\/02\/c903d433.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1279\" height=\"122\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The JSON response will include the new container\u2019s ID and any warnings arising from its creation. Send the ID in a call to the <code>\/containers\/:id\/start<\/code> endpoint:<\/p>\n<pre>curl http:\/\/127.0.0.1:2375\/v1.41\/containers\/abc123\/start -X POST<\/pre>\n<p>The container will now be running on the Docker host.<\/p>\n<h3 id=\"cleaning-up-containers\"><span class=\"ez-toc-section\" id=\"Cleaning_Up_Containers\"><\/span>Cleaning Up Containers<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Remove stopped containers by issuing a <code>POST<\/code> request to the <code>\/containers\/prune<\/code> endpoint:<\/p>\n<pre>curl http:\/\/127.0.0.1:2375\/v1.41\/containers\/prune -X POST<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15749\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/csit\/2022\/02\/0d44abf5.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1279\" height=\"234\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You\u2019ll be issued a JSON response with <code>ContainersDeleted<\/code> and <code>SpaceReclaimed<\/code> fields. <code>ContainersDeleted<\/code> is an array of the container IDs that were successfully removed. <code>SpaceReclaimed<\/code> informs of you the total storage space freed in bytes.<\/p>\n<p>This endpoint accepts two query string parameters to constrain the operation. The <code>until<\/code> parameter limits the deletion to containers created before a given time, such as <code>until=10m<\/code> or <code>until=2022-03-01<\/code>. The <code>label<\/code> option filters to containers with or without given labels; setting <code>label=demo=example<\/code> will only remove containers with the <code>demo=example<\/code> label.<\/p>\n<h3 id=\"listing-images\"><span class=\"ez-toc-section\" id=\"Listing_Images\"><\/span>Listing Images<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The <code>\/images\/json<\/code> endpoint is used to enumerate the images stored on the Docker host:<\/p>\n<pre>curl http:\/\/127.0.0.1:2375\/v1.41\/images\/json<\/pre>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15752\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/csit\/2022\/02\/685441b2.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1279\" height=\"486\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can use filters to alter the contents of the response. These are supplied as a JSON object in the <code>filters<\/code> query string parameter, similarly to the container list API. One noteworthy option is <code>reference<\/code> which selects the image with a given tag: <code>filters={\"reference\":\"hello-world:latest\"}<\/code>.<\/p>\n<h3 id=\"building-images\"><span class=\"ez-toc-section\" id=\"Building_Images\"><\/span>Building Images<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can use the API to build new Docker images from Dockerfiles. The <code>\/build<\/code> endpoint should be sent a <code>tar<\/code> archive. The contents of this archive will be used as the image\u2019s build context. The archive should include Dockerfile containg the instructions for the build.<\/p>\n<pre>cat context.tar | curl http:\/\/127.0.0.1:2375\/v1.41\/build?t=example-image:latest -X POST<\/pre>\n<p>The command above will send <code>context.tar<\/code> to the Docker daemon and build an image using the <code>Dockerfile<\/code> within. The image will be tagged as <code>example-image:latest<\/code> and stored on the Docker host.<\/p>\n<p>This endpoint accepts many additional query string parameters that match the functionality of the <code>docker build<\/code> CLI. These include <code>dockerfile=path\/to\/dockerfile<\/code>, to specify the path to the build context\u2019s Dockerfile, <code>rm=true<\/code>, which deletes inter<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>te containers created by the build, and <code>pull=true<\/code> to try and acquire updated versions of images referenced by the Dockerfile.<\/p>\n<p>The API requires your client stay connected until the build completes. The build will be cancelled if the network drops and the connection is closed.<\/p>\n<h3 id=\"listing-daemon-event-logs\"><span class=\"ez-toc-section\" id=\"Listing_Daemon_Event_Logs\"><\/span>Listing Daemon Event Logs<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The <code>\/events<\/code> API surfaces the daemon event log data that\u2019s also accessible with the <code>docker events<\/code> CLI command. This endpoint streams events in real-time as they happen.<\/p>\n<pre>curl http:\/\/127.0.0.1:2375\/v1.41\/events<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15750\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/csit\/2022\/02\/c47576a4.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1279\" height=\"542\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Several different kinds of event are exposed including container creations, image tags, volume mounts, and network changes. You can filter to a specific kind of event using the <code>type<\/code> field of the <code>filters<\/code> query parameter:<\/p>\n<pre># Only get container events&#13;\ncurl http:\/\/127.0.0.1:2375\/v1.41\/events?filters={'type':'container'}<\/pre>\n<p>It\u2019s also possible to constrain to events relating to a specific object:<\/p>\n<pre># Get events pertaining to the container with ID abc123&#13;\ncurl http:\/\/127.0.0.1:2375\/v1.41\/events?filters={'container':'id'}<\/pre>\n<p>Two other query string parameters, <code>since<\/code> and <code>until<\/code>, let you specify a timestamp range to surface historical events within.<\/p>\n<h3 id=\"getting-system-information\"><span class=\"ez-toc-section\" id=\"Getting_System_Information\"><\/span>Getting System Information<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The Docker Engine API can be used to get information about the physical host it\u2019s running on:<\/p>\n<pre>curl http:\/\/127.0.0.1:2375\/v1.41\/info<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15751\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/csit\/2022\/02\/cceade63.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1279\" height=\"682\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This endpoint provides extensive details describing the current state and configuration of the host and Docker daemon. Fields in the response include counts of the number of running, paused, and stopped containers, the path to Docker\u2019s installation directory, hardware and OS details, and the server\u2019s Swarm configuration when it\u2019s operating within a cluster.<\/p>\n<h2 id=\"conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The Docker Engine API gives you a way to send commands to your host\u2019s Docker daemon over HTTP. This makes it simpler to script programmatic interactions without becoming reliant on specific Docker CLI behaviors. The API can also be used to remotely manage your Docker servers for enhanced monitoring and ease of maintenance.<\/p>\n<p>While calling the API should be straightforward, you need to pay attention to the security protections around your TCP socket. Avoid exposing the socket on your network unless it\u2019s secured with TLS so only approved clients can connect. Omitting this extra set up stage could prove costly if an intruder discovers your daemon instance and begins issuing commands.<\/p>\n<p>You can make it even easier to use the API within your own applications by adopting <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/engine\/api\/sdk\/\">one of the SDKs<\/a>. Either an official or community-provided option is available for all popular programming languages, including C, C#, C++, Go, Java, NodeJS, PHP, Python, and Ruby. The SDKs wrap the API\u2019s endpoints in convenient classes and functions to call from your code, reducing the amount of boilerplate needed to interact with a Docker installation.<\/p>\n<\/div>\n<p><script>\n setTimeout(function(){\n  !function(f,b,e,v,n,t,s)\n  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\n  n.callMethod.apply(n,arguments):n.queue.push(arguments)};\n  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';\n  n.queue=[];t=b.createElement(e);t.async=!0;\n  t.src=v;s=b.getElementsByTagName(e)[0];\n  s.parentNode.insertBefore(t,s) } (window, document,'script',\n  'https:\/\/connect.facebook.net\/en_US\/fbevents.js');\n   fbq('init', '335401813750447');\n   fbq('track', 'PageView');\n  },3000);\n<\/script><\/p>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.howtogeek.com\/devops\/how-to-get-started-using-the-docker-engine-api\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;How to Get Started Using the Docker Engine API&#8221; Docker Engine exposes a REST API which you can use to control your containers without the docker CLI. The API exposes equivalent functionality using HTTP network calls. You can script common Docker operations using your favorite programming language or remotely control one of your hosts. The&#8230;<\/p>\n","protected":false},"author":1,"featured_media":459205,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.howtogeek.com\/wp-content\/uploads\/csit\/2021\/09\/993634a1.png?height=200p&trim=2,2,2,2","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-459204","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/459204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=459204"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/459204\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/459205"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=459204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=459204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=459204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}