Unable to start elasticsearch docker container

Viewed 8860

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

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.

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


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.

Related