-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathget-started-stack-docker.html
810 lines (773 loc) · 41.5 KB
/
get-started-stack-docker.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>Running the Elastic Stack ("ELK") on Docker | Getting Started [8.2] | Elastic</title>
<meta class="elastic" name="content" content="Running the Elastic Stack ("ELK") on Docker | Getting Started [8.2]">
<link rel="home" href="index.html" title="Getting Started [8.2]"/>
<link rel="up" href="index.html" title="Getting Started [8.2]"/>
<link rel="prev" href="get-started-elastic-stack.html" title="Getting started with the Elastic Stack"/>
<link rel="next" href="get-started-kubernetes.html" title="Running the Elastic Stack on Kubernetes"/>
<meta class="elastic" name="product_version" content="8.2"/>
<meta class="elastic" name="product_name" content="Elastic Stack"/>
<meta class="elastic" name="website_area" content="documentation"/>
<meta name="DC.type" content="Learn/Docs/Elastic Stack/Getting started/8.2"/>
<meta name="DC.subject" content="Elastic Stack"/>
<meta name="DC.identifier" content="8.2"/>
<meta name="robots" content="noindex,nofollow"/>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.optimizely.com/js/18132920325.js"></script>
<link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="/manifest.json">
<meta name="apple-mobile-web-app-title" content="Elastic">
<meta name="application-name" content="Elastic">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/mstile-144x144.png">
<meta name="theme-color" content="#ffffff">
<meta name="naver-site-verification" content="936882c1853b701b3cef3721758d80535413dbfd" />
<meta name="yandex-verification" content="d8a47e95d0972434" />
<meta name="localized" content="true" />
<meta name="st:robots" content="follow,index" />
<meta property="og:image" content="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt280217a63b82a734/6202d3378b1f312528798412/elastic-logo.svg" />
<meta property="og:image:width" content="500" />
<meta property="og:image:height" content="172" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link rel="apple-touch-icon-precomposed" sizes="64x64" href="/favicon_64x64_16bit.png">
<link rel="apple-touch-icon-precomposed" sizes="32x32" href="/favicon_32x32.png">
<link rel="apple-touch-icon-precomposed" sizes="16x16" href="/favicon_16x16.png">
<!-- Give IE8 a fighting chance -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="/guide/static/styles-v1.css" />
</head>
<!--© 2015-2025 Elasticsearch B.V. -->
<!-- All Elastic documentation is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. -->
<!-- http://creativecommons.org/licenses/by-nc-nd/4.0/ -->
<body>
<!-- Google Tag Manager -->
<script>dataLayer = [];</script><noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-58RLH5" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-58RLH5');</script>
<!-- End Google Tag Manager -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-12395217-16"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-12395217-16');
</script>
<!-- Google Tag Manager for GA4 -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-KNJMG2M');</script>
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KNJMG2M" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager for GA4-->
<div id='elastic-nav' style="display:none;"></div>
<script src='https://www.elastic.co/elastic-nav.js'></script>
<div class="main-container">
<section id="content" >
<div class="content-wrapper">
<section id="guide" lang="en">
<div class="container-fluid">
<div class="row pb-3">
<div class="col-12 order-2 col-md-4 order-md-1 col-lg-3 h-almost-full-md sticky-top-md" id="left_col">
<!-- The TOC is appended here -->
</div>
<div class="col-12 order-1 col-md-8 order-md-2 col-lg-7 order-lg-2 guide-section" id="middle_col">
<!-- start body -->
<div class="navheader">
<span class="prev">
<a href="get-started-elastic-stack.html">« Getting started with the Elastic Stack</a>
</span>
<span class="next">
<a href="get-started-kubernetes.html">Running the Elastic Stack on Kubernetes »</a>
</span>
</div>
<div class="book" lang="en">
<div class="titlepage">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="/guide/">Elastic Docs</a></span>
<span class="chevron-right">›</span><span class="breadcrumb-link"><a href="index.html">Getting Started [8.2]</a></span>
</div>
<div>
<div><h1 class="title"><a id="id-1"></a>Running the Elastic Stack ("ELK") on Docker</h1><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
</div>
<!--EXTRA-->
</div>
<div id="content">
<div id="url-to-v3" class="version-warning">
<strong>IMPORTANT</strong>: This documentation is no longer updated. Refer to <a href="https://www.elastic.co/support/eol">Elastic's version policy</a> and the <a href="https://www.elastic.co/docs">latest documentation</a>.
</div>
<div class="chapter">
<div class="titlepage"><div><div>
<div class="position-relative"><h2 class="title"><a id="get-started-stack-docker"></a>Running the Elastic Stack ("ELK") on Docker</h2><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
</div></div></div>
<p>The Elastic Docker registry contains Docker images for all the products in
the Elastic Stack: <a href="https://www.docker.elastic.co/" class="ulink" target="_top">https://www.docker.elastic.co/</a>.</p>
<p>You can <a class="xref" href="get-started-stack-docker.html#run-docker-secure" title="Start Elasticsearch and Kibana in Docker">start the Elastic Stack in Docker</a> with security enabled
and configured by default. This option is great for quickly getting started with
Elasticsearch and Kibana for testing and development.</p>
<p>You can also <a class="xref" href="get-started-stack-docker.html#get-started-docker-tls" title="Start the Elastic Stack with Docker Compose">start the Elastic Stack with Docker Compose</a> to
create a secured, multi-node cluster with a connected Kibana instance. This
option results in a more resilient cluster with greater capacity and reliability.</p>
<div class="position-relative"><h3><a id="run-docker-secure"></a>Start Elasticsearch and Kibana in Docker</h3><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>Starting in Elasticsearch 8.0, security is enabled and configured by default.</p>
<p>If you’re starting a single-node Elasticsearch cluster in a Docker container, security
will be automatically enabled and configured for you. When you start Elasticsearch for
the first time, the following security configuration occurs automatically:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<a href="/guide/en/elasticsearch/reference/8.2/configuring-stack-security.html#stack-security-certificates" class="ulink" target="_top">Certificates and keys</a> are generated
for the transport and HTTP layers.
</li>
<li class="listitem">
The Transport Layer Security (TLS) configuration settings are written to
<code class="literal">elasticsearch.yml</code>.
</li>
<li class="listitem">
A password is generated for the <code class="literal">elastic</code> user.
</li>
<li class="listitem">
An enrollment token is generated for Kibana.
</li>
<li class="listitem">
An enrollment token is generated for other Elasticsearch nodes.
</li>
</ul>
</div>
<p>You can then <a href="/guide/en/kibana/8.2/docker.html" class="ulink" target="_top">start Kibana</a> and enter the enrollment
token, which is valid for 30 minutes. This token automatically applies the
security settings from your Elasticsearch cluster, authenticates to Elasticsearch with the
<code class="literal">kibana</code> service account, and writes the security configuration to <code class="literal">kibana.yml</code>.</p>
<div class="position-relative"><h4><a id="_prerequisites"></a>Prerequisites</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
Install the appropriate <a href="https://docs.docker.com/get-docker/" class="ulink" target="_top">Docker application</a>
for your operating system.
</li>
<li class="listitem">
<p>Pull the Elasticsearch Docker image.</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker pull docker.elastic.co/elasticsearch/elasticsearch:8.2.3</pre>
</div>
</li>
<li class="listitem">
<p>Pull the Kibana Docker image.</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker pull docker.elastic.co/kibana/kibana:8.2.3</pre>
</div>
</li>
</ol>
</div>
<div class="position-relative"><h4><a id="docker-start-enroll"></a>Start a single-node Elasticsearch cluster and enroll Kibana</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>The following command starts a single-node Elasticsearch cluster for development or
testing.</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
<p>Create an <code class="literal">elastic</code> network for your containers.</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker network create elastic</pre>
</div>
</li>
<li class="listitem">
<p>Start Elasticsearch in Docker. A password is generated for the <code class="literal">elastic</code> user and
output to the terminal, plus enrollment tokens for enrolling Kibana and adding
additional nodes to your cluster.</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker run --name es01 --net elastic -p 9200:9200 -it docker.elastic.co/elasticsearch/elasticsearch:8.2.3</pre>
</div>
<div class="tip admon">
<div class="icon"></div>
<div class="admon_content">
<p>You might need to scroll back a bit in the terminal to view the password
and enrollment token.</p>
</div>
</div>
</li>
<li class="listitem">
Copy the generated password and enrollment token and save them in a secure
location. These values are shown only when you start Elasticsearch for the first time.
</li>
<li class="listitem">
<p>Copy the <code class="literal">http_ca.crt</code> security certificate from your Docker container to
your local machine.</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker cp es01:/usr/share/elasticsearch/config/certs/http_ca.crt .</pre>
</div>
</li>
<li class="listitem">
<p>Open a new terminal and verify that you can connect to your Elasticsearch
cluster by making an authenticated call, using the <code class="literal">http_ca.crt</code> file that you
copied from your Docker container. Enter the password for the <code class="literal">elastic</code> user
when prompted.</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">curl --cacert http_ca.crt -u elastic https://localhost:9200</pre>
</div>
<p>If the connection is successful, the command returns a response like this:</p>
<div class="pre_wrapper lang-js">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-js">{
"name" : "Cp8oag6",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",
"version" : {
"number" : "8.2.3",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "f27399d",
"build_date" : "2021-11-04T12:35:26.989068569Z",
"build_snapshot" : false,
"lucene_version" : "9.0.0",
"minimum_wire_compatibility_version" : "7.16.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}</pre>
</div>
</li>
<li class="listitem">
<p>In a new terminal session, start Kibana and connect it to your Elasticsearch container:</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker run --name kibana --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.2.3</pre>
</div>
<p>When you start Kibana, a unique link is output to your terminal.</p>
</li>
<li class="listitem">
<p>To access Kibana, click the generated link in your terminal.</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
In your browser, paste the enrollment token that you copied when starting
Elasticsearch and click the button to connect your Kibana instance with Elasticsearch.
</li>
<li class="listitem">
Log in to Kibana as the <code class="literal">elastic</code> user with the password that was generated
when you started Elasticsearch.
</li>
</ol>
</div>
</li>
</ol>
</div>
<div class="position-relative"><h4><a id="docker-enroll-nodes"></a>Enroll additional nodes</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>When you start Elasticsearch for the first time, the installation process configures a single-node cluster by default. This process also generates an enrollment token
and prints it to your terminal. If you want a node to join an existing cluster,
start the new node with the generated enrollment token.</p>
<div class="sidebar">
<div class="titlepage"><div><div>
<p class="title"><strong>Generating enrollment tokens</strong></p>
</div></div></div>
<p>The enrollment token is valid for 30 minutes. If you need to generate a
new enrollment token, run the
<a href="/guide/en/elasticsearch/reference/8.2/create-enrollment-token.html" class="ulink" target="_top"><code class="literal">elasticsearch-create-enrollment-token</code></a> tool
on your existing node. This tool is available in the Elasticsearch <code class="literal">bin</code> directory of the
Docker container.</p>
<p>For example, run the following command on the existing <code class="literal">es01</code> node to
generate an enrollment token for new Elasticsearch nodes:</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node</pre>
</div>
</div>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
In the terminal where you started your first node, copy the generated
enrollment token for adding new Elasticsearch nodes.
</li>
<li class="listitem">
<p>On your new node, start Elasticsearch and include the generated enrollment token.</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker run -e ENROLLMENT_TOKEN="<token>" --name es02 --net elastic -it docker.elastic.co/elasticsearch/elasticsearch:8.2.3</pre>
</div>
<p>Elasticsearch is now configured to join the existing cluster.</p>
</li>
</ol>
</div>
<p>If you experience issues where the container where your first node is running
exits when your second node starts, explicitly set values for the JVM heap size.
To <a href="/guide/en/elasticsearch/reference/8.2/docker.html#docker-set-heap-size" class="ulink" target="_top">manually configure the heap size</a>,
include the <code class="literal">ES_JAVA_OPTS</code> variable and set values for <code class="literal">-Xms</code> and <code class="literal">-Xmx</code> when
starting each node. For example, the following command starts node <code class="literal">es02</code> and
sets the minimum and maximum JVM heap size to 1 GB:</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker run -e ES_JAVA_OPTS="-Xms1g -Xmx1g" -e ENROLLMENT_TOKEN="<token>" --name es02 -p 9201:9200 --net elastic -it docker.elastic.co/elasticsearch/elasticsearch:8.2.3</pre>
</div>
<div class="position-relative"><h4><a id="docker-generate"></a>Generate passwords and enrollment tokens</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>If you need to reset the password for the <code class="literal">elastic</code> user or other
built-in users, run the <a href="/guide/en/elasticsearch/reference/8.2/reset-password.html" class="ulink" target="_top"><code class="literal">elasticsearch-reset-password</code></a>
tool. This tool is available in the Elasticsearch <code class="literal">bin</code> directory of the Docker container.</p>
<p>For example, to reset the password for the <code class="literal">elastic</code> user:</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic</pre>
</div>
<p>If you need to generate new enrollment tokens for Kibana or Elasticsearch nodes, run the
<a href="/guide/en/elasticsearch/reference/8.2/create-enrollment-token.html" class="ulink" target="_top"><code class="literal">elasticsearch-create-enrollment-token</code></a> tool.
This tool is available in the Elasticsearch <code class="literal">bin</code> directory of the Docker container.</p>
<p>For example, to generate a new enrollment token for Kibana:</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana</pre>
</div>
<div class="position-relative"><h4><a id="docker-remove-containers"></a>Remove Docker containers</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>To remove the containers and their network, run:</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker network rm elastic
docker rm es01
docker rm kibana</pre>
</div>
<div class="position-relative"><h3><a id="get-started-docker-tls"></a>Start the Elastic Stack with Docker Compose</h3><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>To get a multi-node Elasticsearch cluster and Kibana up and running in Docker with
security enabled, you can use Docker Compose.</p>
<p>This configuration provides a simple method of starting a secured cluster that
you can use for development before building a distributed deployment with
multiple hosts.</p>
<div class="position-relative"><h4><a id="_prerequisites_2"></a>Prerequisites</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>Install the appropriate <a href="https://docs.docker.com/get-docker/" class="ulink" target="_top">Docker application</a>
for your operating system.</p>
<p>If you’re running on Linux, install <a href="https://docs.docker.com/compose/install/" class="ulink" target="_top">Docker Compose</a>.</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>Make sure that Docker is allotted at least 4GB of memory. In Docker Desktop,
you configure resource usage on the Advanced tab in Preferences (macOS) or
Settings (Windows).</p>
</div>
</div>
<div class="position-relative"><h4><a id="_prepare_the_environment"></a>Prepare the environment</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>Create the following configuration files in a new, empty directory. These files
are also available from the
<a href="https://github.com/elastic/elasticsearch/tree/8.2/docs/reference/setup/install/docker/" class="ulink" target="_top">elastic/elasticsearch</a>
repository on GitHub.</p>
<div class="position-relative"><h5><a id="docker-env-file"></a><code class="literal">.env</code></h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>The <code class="literal">.env</code> file sets environment variables that are used when you run the
<code class="literal">docker-compose.yml</code> configuration file. Ensure that you specify a strong
password for the <code class="literal">elastic</code> and <code class="literal">kibana_system</code> users with the
<code class="literal">ELASTIC_PASSWORD</code> and <code class="literal">KIBANA_PASSWORD</code> variables. These variable are
referenced by the <code class="literal">docker-compose.yml</code> file.</p>
<div class="pre_wrapper lang-txt">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-txt"># Password for the 'elastic' user (at least 6 characters)
ELASTIC_PASSWORD=
# Password for the 'kibana_system' user (at least 6 characters)
KIBANA_PASSWORD=
# Version of Elastic products
STACK_VERSION=8.2.3
# Set the cluster name
CLUSTER_NAME=docker-cluster
# Set to 'basic' or 'trial' to automatically start the 30-day trial
LICENSE=basic
#LICENSE=trial
# Port to expose Elasticsearch HTTP API to the host
ES_PORT=9200
#ES_PORT=127.0.0.1:9200
# Port to expose Kibana to the host
KIBANA_PORT=5601
#KIBANA_PORT=80
# Increase or decrease based on the available host memory (in bytes)
MEM_LIMIT=1073741824
# Project namespace (defaults to the current folder name if not set)
#COMPOSE_PROJECT_NAME=myproject</pre>
</div>
<div class="position-relative"><h5><a id="docker-compose-file"></a><code class="literal">docker-compose.yml</code></h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>This <code class="literal">docker-compose.yml</code> file creates a three-node secure Elasticsearch cluster with authentication and network encryption enabled, and a Kibana instance securely connected to it.</p>
<div class="sidebar">
<div class="titlepage"><div><div>
<p class="title"><strong>Exposing ports</strong></p>
</div></div></div>
<p>This configuration exposes port <code class="literal">9200</code> on all network interfaces. Because
of how Docker handles ports, a port that isn’t bound to <code class="literal">localhost</code> leaves your
Elasticsearch cluster publicly accessible, potentially ignoring any firewall settings.
If you don’t want to expose port <code class="literal">9200</code> to external hosts, set the value for
<code class="literal">ES_PORT</code> in the <code class="literal">.env</code> file to something like <code class="literal">127.0.0.1:9200</code>. Elasticsearch will
then only be accessible from the host machine itself.</p>
</div>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">version: "2.2"
services:
setup:
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
volumes:
- certs:/usr/share/elasticsearch/config/certs
user: "0"
command: >
bash -c '
if [ x${ELASTIC_PASSWORD} == x ]; then
echo "Set the ELASTIC_PASSWORD environment variable in the .env file";
exit 1;
elif [ x${KIBANA_PASSWORD} == x ]; then
echo "Set the KIBANA_PASSWORD environment variable in the .env file";
exit 1;
fi;
if [ ! -f config/certs/ca.zip ]; then
echo "Creating CA";
bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip;
unzip config/certs/ca.zip -d config/certs;
fi;
if [ ! -f config/certs/certs.zip ]; then
echo "Creating certs";
echo -ne \
"instances:\n"\
" - name: es01\n"\
" dns:\n"\
" - es01\n"\
" - localhost\n"\
" ip:\n"\
" - 127.0.0.1\n"\
" - name: es02\n"\
" dns:\n"\
" - es02\n"\
" - localhost\n"\
" ip:\n"\
" - 127.0.0.1\n"\
" - name: es03\n"\
" dns:\n"\
" - es03\n"\
" - localhost\n"\
" ip:\n"\
" - 127.0.0.1\n"\
> config/certs/instances.yml;
bin/elasticsearch-certutil cert --silent --pem -out config/certs/certs.zip --in config/certs/instances.yml --ca-cert config/certs/ca/ca.crt --ca-key config/certs/ca/ca.key;
unzip config/certs/certs.zip -d config/certs;
fi;
echo "Setting file permissions"
chown -R root:root config/certs;
find . -type d -exec chmod 750 \{\} \;;
find . -type f -exec chmod 640 \{\} \;;
echo "Waiting for Elasticsearch availability";
until curl -s --cacert config/certs/ca/ca.crt https://es01:9200 | grep -q "missing authentication credentials"; do sleep 30; done;
echo "Setting kibana_system password";
until curl -s -X POST --cacert config/certs/ca/ca.crt -u elastic:${ELASTIC_PASSWORD} -H "Content-Type: application/json" https://es01:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done;
echo "All done!";
'
healthcheck:
test: ["CMD-SHELL", "[ -f config/certs/es01/es01.crt ]"]
interval: 1s
timeout: 5s
retries: 120
es01:
depends_on:
setup:
condition: service_healthy
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
volumes:
- certs:/usr/share/elasticsearch/config/certs
- esdata01:/usr/share/elasticsearch/data
ports:
- ${ES_PORT}:9200
environment:
- node.name=es01
- cluster.name=${CLUSTER_NAME}
- cluster.initial_master_nodes=es01,es02,es03
- discovery.seed_hosts=es02,es03
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
- bootstrap.memory_lock=true
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=certs/es01/es01.key
- xpack.security.http.ssl.certificate=certs/es01/es01.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.http.ssl.verification_mode=certificate
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.key=certs/es01/es01.key
- xpack.security.transport.ssl.certificate=certs/es01/es01.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=${LICENSE}
mem_limit: ${MEM_LIMIT}
ulimits:
memlock:
soft: -1
hard: -1
healthcheck:
test:
[
"CMD-SHELL",
"curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
]
interval: 10s
timeout: 10s
retries: 120
es02:
depends_on:
- es01
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
volumes:
- certs:/usr/share/elasticsearch/config/certs
- esdata02:/usr/share/elasticsearch/data
environment:
- node.name=es02
- cluster.name=${CLUSTER_NAME}
- cluster.initial_master_nodes=es01,es02,es03
- discovery.seed_hosts=es01,es03
- bootstrap.memory_lock=true
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=certs/es02/es02.key
- xpack.security.http.ssl.certificate=certs/es02/es02.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.http.ssl.verification_mode=certificate
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.key=certs/es02/es02.key
- xpack.security.transport.ssl.certificate=certs/es02/es02.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=${LICENSE}
mem_limit: ${MEM_LIMIT}
ulimits:
memlock:
soft: -1
hard: -1
healthcheck:
test:
[
"CMD-SHELL",
"curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
]
interval: 10s
timeout: 10s
retries: 120
es03:
depends_on:
- es02
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
volumes:
- certs:/usr/share/elasticsearch/config/certs
- esdata03:/usr/share/elasticsearch/data
environment:
- node.name=es03
- cluster.name=${CLUSTER_NAME}
- cluster.initial_master_nodes=es01,es02,es03
- discovery.seed_hosts=es01,es02
- bootstrap.memory_lock=true
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=certs/es03/es03.key
- xpack.security.http.ssl.certificate=certs/es03/es03.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.http.ssl.verification_mode=certificate
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.key=certs/es03/es03.key
- xpack.security.transport.ssl.certificate=certs/es03/es03.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=${LICENSE}
mem_limit: ${MEM_LIMIT}
ulimits:
memlock:
soft: -1
hard: -1
healthcheck:
test:
[
"CMD-SHELL",
"curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
]
interval: 10s
timeout: 10s
retries: 120
kibana:
depends_on:
es01:
condition: service_healthy
es02:
condition: service_healthy
es03:
condition: service_healthy
image: docker.elastic.co/kibana/kibana:${STACK_VERSION}
volumes:
- certs:/usr/share/kibana/config/certs
- kibanadata:/usr/share/kibana/data
ports:
- ${KIBANA_PORT}:5601
environment:
- SERVERNAME=kibana
- ELASTICSEARCH_HOSTS=https://es01:9200
- ELASTICSEARCH_USERNAME=kibana_system
- ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD}
- ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=config/certs/ca/ca.crt
mem_limit: ${MEM_LIMIT}
healthcheck:
test:
[
"CMD-SHELL",
"curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'",
]
interval: 10s
timeout: 10s
retries: 120
volumes:
certs:
driver: local
esdata01:
driver: local
esdata02:
driver: local
esdata03:
driver: local
kibanadata:
driver: local</pre>
</div>
<div class="position-relative"><h4><a id="_start_your_cluster_with_security_enabled_and_configured"></a>Start your cluster with security enabled and configured</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
<p>Modify the <code class="literal">.env</code> file and enter strong password values for both the
<code class="literal">ELASTIC_PASSWORD</code> and <code class="literal">KIBANA_PASSWORD</code> variables.</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>You must use the <code class="literal">ELASTIC_PASSWORD</code> value for further interactions with
the cluster. The <code class="literal">KIBANA_PASSWORD</code> value is only used internally when
configuring Kibana.</p>
</div>
</div>
</li>
<li class="listitem">
<p>Create and start the three-node Elasticsearch cluster and Kibana instance:</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker-compose up -d</pre>
</div>
</li>
<li class="listitem">
When the deployment has started, open a browser and navigate to <a href="http://localhost:5601" class="ulink" target="_top">http://localhost:5601</a> to
access Kibana, where you can load sample data and interact with your cluster. Log in as the <code class="literal">elastic</code> user with
the <code class="literal">ELASTIC_PASSWORD</code> value to get access.
</li>
</ol>
</div>
<div class="position-relative"><h4><a id="docker-compose-remove-containers"></a>Stop and remove the deployment</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>When you’re done experimenting, you can remove the network, containers, and
volumes:</p>
<div class="pre_wrapper lang-sh">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-sh">docker-compose down -v</pre>
</div>
<div class="position-relative"><h4><a id="load-settings-file"></a>Load settings from a file</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>Specifying settings for Elasticsearch and Kibana directly in the Docker Compose file is a
convenient way to get started, but loading settings from a file is preferable
after you get past the experimental stage.</p>
<p>For example, to use a custom <code class="literal">es01.yml</code> as the configuration file for the <code class="literal">es01</code>
Elasticsearch node, you can create a bind mount in the <code class="literal">volumes</code> section for the <code class="literal">es01</code>
service.</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml"> volumes:
- ./es01.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ...</pre>
</div>
<p>Similarly, to load Kibana settings from a file, you can add the following mount
in the <code class="literal">volumes</code> section for the <code class="literal">kibana</code> service.</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml"> volumes:
- ./kibana.yml:/usr/share/kibana/config/kibana.yml
- ...</pre>
</div>
<div class="position-relative"><h3><a id="_product_specific_instructions_for_docker"></a>Product-specific instructions for Docker</h3><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/stack-docs/edit/8.2/docs/en/getting-started/get-started-docker.asciidoc">edit</a></div>
<p>See the product-specific documentation for information about running a specific Elastic product in Docker:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<a href="/guide/en/elasticsearch/reference/8.2/docker.html" class="ulink" target="_top">Install Elasticsearch with Docker</a>
</li>
<li class="listitem">
<a href="/guide/en/fleet/8.2/elastic-agent-container.html" class="ulink" target="_top">Run Elastic Agent in a container</a>
</li>
</ul>
</div>
</div>
</div>
</div><div class="navfooter">
<span class="prev">
<a href="get-started-elastic-stack.html">« Getting started with the Elastic Stack</a>
</span>
<span class="next">
<a href="get-started-kubernetes.html">Running the Elastic Stack on Kubernetes »</a>
</span>
</div>
<!-- end body -->
</div>
<div class="col-12 order-3 col-lg-2 order-lg-3 h-almost-full-lg sticky-top-lg" id="right_col">
<div id="sticky_content">
<!-- The OTP is appended here -->
<div class="row">
<div class="col-0 col-md-4 col-lg-0" id="bottom_left_col"></div>
<div class="col-12 col-md-8 col-lg-12">
<div id="rtpcontainer">
<div class="mktg-promo" id="most-popular">
<p class="aside-heading">Most Popular</p>
<div class="pb-2">
<p class="media-type">Video</p>
<a href="https://www.elastic.co/webinars/getting-started-elasticsearch?page=docs&placement=top-video">
<p class="mb-0">Get Started with Elasticsearch</p>
</a>
</div>
<div class="pb-2">
<p class="media-type">Video</p>
<a href="https://www.elastic.co/webinars/getting-started-kibana?page=docs&placement=top-video">
<p class="mb-0">Intro to Kibana</p>
</a>
</div>
<div class="pb-2">
<p class="media-type">Video</p>
<a href="https://www.elastic.co/webinars/introduction-elk-stack?page=docs&placement=top-video">
<p class="mb-0">ELK for Logs & Metrics</p>
</a>
</div>
</div>
</div>
<!-- Feedback widget -->
<div id="feedbackWidgetContainer"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<div id='elastic-footer'></div>
<script src='https://www.elastic.co/elastic-footer.js'></script>
<!-- Footer Section end-->
</section>
</div>
<!-- Feedback modal -->
<div id="feedbackModalContainer"></div>
<script src="/guide/static/jquery.js"></script>
<script type="text/javascript" src="/guide/static/docs-v1.js"></script>
<script type="text/javascript">
window.initial_state = {}</script>
</body>
</html>