I have installed docker on arch os and I have been using docker for a while now. Recently, docker run -v "$PWD/esdata":/usr/share/elasticsearch/data -d -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS="-Xms1g -Xmx1g" elasticsearch:5.1
no longer works and the container automatically stops in a sec. I then tried the solution given here. By adding tail -f /dev/null
to the end of my previous command. Now, the container runs but I get nothing when I go to localhost:9200

- 27,626
- 16
- 90
- 108

- 714
- 2
- 7
- 20
-
"Now, the container runs": because you are running the `tail` command in it. This is certainly not what you want. Always be sure to understand what a command does before you type it. – Henry Jul 22 '17 at 09:02
-
can you tell the log of container by docker logs
? – Himanshu sharma Jul 22 '17 at 10:26 -
here https://pastebin.com/rBujntps – Reuben_v1 Jul 22 '17 at 10:31
-
Have you tried to connect to localhost:9300, since your command has duplicate port option? Btw, container must have something running in the foreground in order to run, if foreground process stops, the contaier will also stop. This is the reason why your container runs when you add tail command. – Branimir Đurek Jul 23 '17 at 18:36
4 Answers
Came across the same issue with below command
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.2.4
My environment is docker on MacOS. As per 'For those using Windows or OSX ' section in this article Docker memory needs to be 4GB min. After changing the memory limit, container started without any issues.

- 261
- 2
- 8
-
3I had the same problem in Manjaro. This is how I solved it `docker run --memory="4g" --name elastic -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.15.1` – Eduardo Rodriguez Oct 18 '21 at 22:06
There is a problem in setting the ES_JAVA_OPTS
while running the image, it should be:
docker run -d -p 9200:9200 -p 9300:9300 -e 'ES_JAVA_OPTS: -Xms1g -Xmx1g' elasticsearch:5.1

- 27,626
- 16
- 90
- 108
-
-
@Reuben_v1 seems mounting a volume to `Docker` container has a problem. – Arpit Aggarwal Jul 22 '17 at 10:45
in my case, it was a permission issue so I added permission next to the volume:
this one: //read, write and execute
version: '3'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
environment:
- discovery.type=single-node
volumes:
- /home/shared-content-initiative/elasticsearch:/usr/share/elasticsearch/data //read, write and execute
- ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml

- 398
- 4
- 17
I tried the following after a lot of research. It works for me now. First, make sure whether you have Java installed if using Elastic Search 5 or 6. For version 7, we don't need it specifically.
Make service active: Open yml file in nano editor for the following settings.
sudo nano /etc/elasticsearch/elasticsearch.yml
Confirm the following settings: (uncomment following lines and they should start in the beginning without any spaces)
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 127.0.0.1
#
# Set a custom port for HTTP:
#
http.port: 9200
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: []
Confirm configuration for jvm.options file at '/etc/elasticsearch/jvm.options':
sudo nano /etc/elasticsearch/jvm.options
Memory allocation Xms
and Xmx
:
Allocate necessary memory not more than 50% for optimal performance. There are other settings you can tweak if you are aware of swappiness and timeout etc., but please don't touch them if you are not sure.
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms4g
-Xmx4g
I have an 8 GB Ram, hence allocated 4GB. Feel free to allocate -Xms2048m
and -Xmx2048m
and so on in the set {1024m, 750m, 512m, 256m}. It is your choice of usage that demands this.
After fixing the above, run the following commands and restart the system. We need to restart since we edited system-wide environment configuration to take effect.
Installation via docker and other mediums at the same time isn't a problem. But, starting service from both ways produces conflicts as the TCP port that listens can't be duplicated. In short, run elastic search service from either docker pulled image, or your local installation. Not both at same time. If you have errors about duplication of ports, make sure to hit the following command:
sudo systemctl stop elasticsearch.service
To have Elasticsearch automatically reload when the system restarts, use the following commands: (If installed via wget & apt / from binaries / any other elastic search installation process other than docker image pull. Just reloading daemon-d is enough for docker (1st command)):
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
It worked for me fine. I hope this clarifies the problem.

- 91
- 1
- 6