I'm following the instructions here https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
and only need one elastic search instance. When I run docker-compose up I get an error saying The compose file docker-compose.yml is invalid because Unsupported config option for services.volumes: 'esdata1'
What am I doing wrong?
My docker-compose file
version: '2.1'
services:
elasticsearch1:
image: docker.elastic.co/elasticsearch/elasticsearch:5.4.0
container_name: elasticsearch1
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
mem_limit: 1g
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- 9200:9200
You seem to have missed the top-level volumes section towards the end of the sample file given here (https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker-prod-cluster-composefile).
Docker Compose v2 reference also specifies this requirement - https://docs.docker.com/compose/compose-file/compose-file-v2/#volumes-volumedriver
Excerpt from the above link:
For version 2 files, named volumes need to be specified with the top-level volumes key.
Related
I am trying to run docker container with Elasticsearch on Windows. The docker-compose.yml file contains following section:
services:
elasticsearch:
image: elasticsearch:$ELK_VERSION
container_name: elasticsearch
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data/elasticsearch:/usr/share/elasticsearch/data
ports:
- 9200:9200
- 9300:9300
networks:
- elk
While trying to run the container an error are being logged to the terminal:
ERROR: [1] bootstrap checks failed
[1]: memory locking requested for elasticsearch process but memory is not locked
How to solve this error? What am i doing wrong?
On Windows, you might have to configure VirtualLock in order for bootstrap.memory_lock=true to work and bootstrap checks to pass.
I have a .env file containing some environment variables. One of them refers to a directory path each user has to specify to make the system work. When I tried it in a Linux host it worked perfectly, but now trying it in Windows 10 system I am having some troubles.
In Linux the ENV looked like this:
DATA_DIRECTORY_PATH=/home/user/absolute/path/to/folder/data/
I tried to just copy the Windows folder path the same way:
DATA_DIRECTORY_PATH=C:\Users\luisc\Luiscri\4Teleco\TFG\TwitterCluster\Proyectos\MABSED\data
However this attempt showed and error saying Error on mounting volume - Directory or file not found
After Googling how the path should be declared in Windows I tried this way:
DATA_DIRECTORY_PATH=//c/Users/luisc/Luiscri/4Teleco/TFG/TwitterCluster/Proyectos/MABSED/data/
And now the error looks like this:
ERROR: for orchestrator Cannot start service orchestrator: b'OCI runtime create failed: container_linux.go:345: starting container process caused "process_linux.go:430: container init caused \\"rootfs_linux.go:58: mounting \\\\\\"/etc/localtime\\\\\\" to rootfs \\\\\\"/var/lib/docker/overlay2/3e21d16a9b19cf553cebccab2454327590e8024abe3643c5577f04f168660488/merged\\\\\\" at \\\\\\"/var/lib/docker/overlay2/3e21d16a9b19cf553cebccab2454327590e8024abe3643c5577f04f168660488/merged/usr/share/zoneinfo/UCT\\\\\\" caused \\\\\\"not a directory\\\\\\"\\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type'
How is the correct way to declare a path in an environment variable in Windows? I come from Linux and I am pretty new to developping on Windows.
Just in case it is needed, here is my docker-compose.yml:
version: '2'
services:
dashboard:
build: demo-dashboard/
ports:
- "8080:8080"
environment:
- ES_ENDPOINT_EXTERNAL=${ES_ENDPOINT_EXTERNAL}
- http.cors.enabled=true
- http.cors.allow-origin=${ES_ENDPOINT_EXTERNAL}
- http.cors.allow-headers=Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
- http.cors.allow-credentials=true
volumes:
- ./demo-dashboard:/usr/src/app
networks:
- dashboard-network
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.7.0
environment:
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- http.cors.enabled=true
- http.cors.allow-origin=http://localhost:8080
- http.cors.allow-headers=Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
- http.cors.allow-credentials=true
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
mem_limit: 1g
cap_add:
- IPC_LOCK
volumes:
- esdata1:/usr/share/elasticsearch/data/
networks:
- dashboard-network
ports:
- 9200:9200
orchestrator:
image: orchestrator-mabsed
build: orchestrator/
environment:
ES_HOST: 'elasticsearch'
tty: true
volumes:
- socialdata1:/usr/src/data/
- "/etc/localtime:/etc/localtime:ro"
networks:
- dashboard-network
streamer:
image: streamer-mabsed
build: streamer/
tty: true
volumes:
- socialdata1:/usr/src/data/
volumes:
esdata1:
driver: local
socialdata1:
driver: local
driver_opts:
type: none
device: ${DATA_DIRECTORY_PATH}
o: bind
networks:
dashboard-network:
driver: bridge
I am using kompose to deploy this docker-compose.yaml
version: '3'
services:
webapp:
build:
context: ../../../
dockerfile: config/docker/dev/Dockerfile-dev
container_name: myWebApp-dev
command: ["/bin/sh", "-ec","sleep 1000"]
image: 'localhost:5002/webapp:1'
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
- ELASTICSEARCH_HOST=elasticsearch
labels:
kompose.image-pull-policy: 'IfNotPresent'
kompose.service.type: nodeport
ports:
- "4000:4000"
- "3000:3000"
depends_on:
- elasticsearch
links:
- elasticsearch
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
container_name: elasticsearch
command: ["/bin/sh", "-ec","sleep 1000"]
environment:
- node.name=elasticsearch
- discovery.seed_hosts=es02
- cluster.initial_master_nodes=elasticsearch,es02
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata01:/usr/share/elasticsearch/data
ports:
- 9200:9200
- 9300:9300
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
container_name: es02
command: ["/bin/sh", "-ec","sleep 1000"]
environment:
- node.name=es02
- discovery.seed_hosts=elasticsearch
- cluster.initial_master_nodes=elasticsearch,es02
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata02:/usr/share/elasticsearch/data
to minikube.
The elasticsearch pod and service are running. However, the webapp cannot access the elasticsearch cluster as I get a connection refused error when curling from within the webapp pod -> curl: (7) Failed to connect to 10.108.5.31 port 9200: Connection refused. Does anyone know what the reason for this problem is and how to fix it?
In elasticsearch section, you have a shell command to sleep. And, never started any elasticsearch instances after that.
command: ["/bin/sh", "-ec","sleep 1000"]
So, looks like, there is no elasticsearch running inside the container and that's why connection refused is happening.
To Fix:
Get rid of command: of elasticsearch and es02, that way, default command will be used.
Note:
Now, When the elasticsearch starts, You will face two error (described below) with this compose yaml in kubernetes. These are unrelated to this post, But I will try to giving you direction where to look.
ERROR: [2] bootstrap checks failed
[1]: memory locking requested for elasticsearch process but memory is not locked
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
Here,
you need to update host system for vm.max_map_count. Exec into minikube virtualbox by minikube ssh and run sudo -s sysctl -w vm.max_map_count=262144 to change the map_count of host kernel. It will work, because docker/container doesn't provide kernel level isolation.
For minikube,
minikube ssh 'sudo -s sysctl -w vm.max_map_count=262144'
ulimit is not available in kompose. See issue here. So either you have to get rid of both, bootstrap.memory_lock=true from environment: sections, or you may need to update the docker image. This question is already asked here in stackoverflow.
So the improved kompose yaml (works well on minikube):
version: '3'
services:
webapp:
build:
context: ../../../
dockerfile: config/docker/dev/Dockerfile-dev
container_name: myWebApp-dev
command: ["/bin/sh", "-ec","sleep 1000"]
image: 'localhost:5002/webapp:1'
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
- ELASTICSEARCH_HOST=elasticsearch
labels:
kompose.image-pull-policy: 'IfNotPresent'
kompose.service.type: nodeport
ports:
- "4000:4000"
- "3000:3000"
depends_on:
- elasticsearch
links:
- elasticsearch
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
container_name: elasticsearch
environment:
- node.name=elasticsearch
- discovery.seed_hosts=es02
- cluster.initial_master_nodes=elasticsearch,es02
- cluster.name=docker-cluster
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- esdata01:/usr/share/elasticsearch/data
ports:
- 9200:9200
- 9300:9300
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
container_name: es02
environment:
- node.name=es02
- discovery.seed_hosts=elasticsearch
- cluster.initial_master_nodes=elasticsearch,es02
- cluster.name=docker-cluster
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- esdata02:/usr/share/elasticsearch/data
However, I would suggest to follow the elasticsearch official doc instead of using compose to install elasticsearch in kubernetes.
How can I set up a service/container to provide elasticsearch with ddev? I have tried some experiments from https://ddev.readthedocs.io/en/latest/users/extend/additional-services/ but don't have enough docker-compose knowhow to do one for elasticsearch.
Edit 2022-03: There is now an official elasticsearch ddev-get add-on for ddev v1.19+, ddev get drud/ddev-elasticsearch, see https://github.com/drud/ddev-elasticsearch.
#thursdaybw provided this recipe in https://github.com/drud/ddev/pull/1320, but it never gained traction and nobody reviewed it, so it's being moved here to percolate and incubate in the community. Please provide your suggestions if you use it.
Edit 2019-09-30: There is now an Elasticsearch example in ddev-contrib at https://github.com/drud/ddev-contrib/tree/master/docker-compose-services/elasticsearch
Basic information (and reviewed examples) for setting up additional services is at https://ddev.readthedocs.io/en/latest/users/extend/additional-services/
version: '3.6'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.1
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- VIRTUAL_HOST=$DDEV_HOSTNAME # This defines the host name the service should be accessible from. This will be sitename.ddev.local
- HTTP_EXPOSE=9200
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- 9200
labels:
# These labels ensure this service is discoverable by ddev
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
volumes:
esdata1:
driver: local
For starting a single node, the given example hasn't helped me out. Without providing further error messages, the container was stopped again. Using the following configuration, I was able to start just one ES node and not as cluster (as given in the previous answer):
version: '3.6'
services:
elasticsearch:
container_name: ddev-${DDEV_SITENAME}-elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.1
environment:
- node.name=${DDEV_SITENAME}-es01
- discovery.type=single-node
- cluster.name=docker-${DDEV_SITENAME}-es-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata01:/usr/share/elasticsearch/data
ports:
- 9200:9200
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.platform: ddev
com.ddev.app-type: elasticsearch
com.ddev.approot: $DDEV_APPROOT
web:
links:
- elasticsearch:elasticsearch
volumes:
esdata01:
driver: local
name: "${DDEV_SITENAME}-es"
Additionally, using this configuration, you could directly access the node using the host name elasticsearch from within another container.
The production setup for elasticsearch in docker looks like this according the official website
version: '2'
services:
elasticsearch1:
image: docker.elastic.co/elasticsearch/elasticsearch:5.5.2
container_name: elasticsearch1
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
mem_limit: 1g
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- esnet
elasticsearch2:
image: docker.elastic.co/elasticsearch/elasticsearch:5.5.2
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "discovery.zen.ping.unicast.hosts=elasticsearch1"
ulimits:
memlock:
soft: -1
hard: -1
mem_limit: 1g
volumes:
- esdata2:/usr/share/elasticsearch/data
networks:
- esnet
volumes:
esdata1:
driver: local
esdata2:
driver: local
networks:
esnet:
Elasticsearch1 is exposed, and it's also connected with Elasticsearch2 by the docker network but they have their own storage.
Now is my question. How is this setup working? Is ES2 (elasticsearch2) doing nothing till ES1 (elasticsearch1) goes down, or is it replicating everything?
Because when I use the API I will always connect with localhost:9200 so I will always access ES1. I don't know what ES1 is doing with this information relative to ES2.
Another case is inside my logstash.conf I have to define the destination of my output:
output {
elasticsearch { hosts => ["elasticsearch1:9200"] }
xxx
}
I keep it internal over the docker network (logstash is linked with elasticsearch1) but I don't know if I also have to define elasticsearch2? Or what is happening now.
How are elasticsearch1 and elasticsearch2 working together?
The two instances act as a cluster. Even if you query one single node, internally your query gets forwarded to all nodes of the cluster (2 in your case) because data is shared across them. Have a look at this official page for more details: https://www.elastic.co/guide/en/elasticsearch/reference/5.5/_basic_concepts.html