{"id":10118,"date":"2023-11-05T21:54:09","date_gmt":"2023-11-05T21:54:09","guid":{"rendered":"https:\/\/putridparrot.com\/blog\/?p=10118"},"modified":"2023-11-05T21:54:09","modified_gmt":"2023-11-05T21:54:09","slug":"running-elasticsearch-in-a-docker-container","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/running-elasticsearch-in-a-docker-container\/","title":{"rendered":"Running Elasticsearch in a Docker container"},"content":{"rendered":"<p>If you want to run elasticsearch in docker you need to use a specific tag, the latest (at the time of writing) is 8.10.4, so let&#8217;s start by pulling that tag using<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ndocker pull elasticsearch:8.10.4\r\n<\/pre>\n<p>I&#8217;ve going to connect Kibana to this instance later, so let&#8217;s create a network as for the two to work with. I&#8217;m calling mine <em>kibana-network<\/em>. <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ndocker network create kibana-network\r\n<\/pre>\n<p>Once completed, run the following to start up elastic search. <\/p>\n<p><em>Note: xpack.security.enabled=false turns off https for testing locally<\/em><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ndocker run -d \r\n   --name elasticsearch \r\n   --net kibana-network \r\n   -p 9200:9200 \r\n   -p 9300:9300 \r\n   -e &quot;discovery.type=single-node&quot; \r\n   -e &quot;xpack.security.enabled=false&quot; \r\n   elasticsearch:8.10.4\r\n<\/pre>\n<p>We want to check this is working so let&#8217;s use CURL to call the elastic search instance, i.e.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncurl -X GET http:\/\/localhost:9200\/_cat\/nodes?v\r\n<\/pre>\n<p>Or from you browser<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nhttp:\/\/localhost:9200\/_cat\/health\r\n<\/pre>\n<p>If all worked, we should see something like<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n1699220835 21:47:15 docker-cluster yellow 1 1 28 28 0 0 1 0 - 96.6%\r\n<\/pre>\n<p>Before we move on let&#8217;s add some data into our instance, we&#8217;ll start by adding an index (again we&#8217;ll use CURL),<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncurl -X PUT http:\/\/localhost:9200\/myservice\r\n<\/pre>\n<p>We should see a response which looks something like this<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nresponse: {&quot;acknowledged&quot;:true,&quot;shards_acknowledged&quot;:true,&quot;index&quot;:&quot;myservice&quot;}\r\n<\/pre>\n<p>Now to add some initial data<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncurl -X POST -H 'Content-Type: application\/json' -d '{ &quot;name&quot;: &quot;Debug&quot;, &quot;description&quot;: &quot;This is a debug message&quot;, &quot;code&quot;: 1, &quot;id&quot;: 2}' \r\n<\/pre>\n<p>If you add a few more entries then we can try a query via CURL to locate this one<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncurl -X GET &quot;localhost:9200\/myservice\/_search?pretty&quot; -H 'Content-Type: application\/json' -d' { &quot;query&quot;: { &quot;match&quot;: { &quot;id&quot;: &quot;2&quot; } } }'\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you want to run elasticsearch in docker you need to use a specific tag, the latest (at the time of writing) is 8.10.4, so let&#8217;s start by pulling that tag using docker pull elasticsearch:8.10.4 I&#8217;ve going to connect Kibana to this instance later, so let&#8217;s create a network as for the two to work [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[143],"tags":[],"class_list":["post-10118","post","type-post","status-publish","format-standard","hentry","category-elasticsearch"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/10118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=10118"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/10118\/revisions"}],"predecessor-version":[{"id":10126,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/10118\/revisions\/10126"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=10118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=10118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=10118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}