When trying to bring up a project with a webapp (using elixir/ecto as backend language),a postgres database, elasticsearch, and kibana using following docker-compose.yaml file:
version: '3'
services:
registry:
restart: always
image: registry:2
ports:
- 443:443
volumes:
- /path/data:/var/lib/registry
- /path/certs:/registry/certs
- /path/auth:/registry/auth
webapp:
build:
context: ../../../
dockerfile: config/docker/dev/Dockerfile-dev
container_name: MyWebApp-dev
image: 'localhost:443/123'
environment:
- ELASTICSEARCH_URL=http://localhost:9200
- ELASTICSEARCH_HOST=localhost
ports:
- "4000:4000"
- "3000:3000"
depends_on:
- db
- elasticsearch
- kibana
networks:
- esnet
db:
image: postgres:10
container_name: db
environment:
- POSTGRES_USER=paul
- POSTGRES_PASSWORD=SilviaZita1
- POSTGRES_DB=snitch_dev
networks:
- esnet
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
- 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
networks:
- esnet
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
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata02:/usr/share/elasticsearch/data
networks:
- esnet
kibana:
image: docker.elastic.co/kibana/kibana:7.0.1
ports:
- "5601:5601"
container_name: kibana
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
- ELASTICSEARCH_HOST=elasticsearch
depends_on:
- elasticsearch
networks:
- esnet
volumes:
esdata01:
driver: local
esdata02:
driver: local
networks:
esnet:
,
I am getting following error:
** (Mix) Index products could not be created. MyWebApp-dev | MyWebApp-dev | %HTTPoison.Error{id: nil, reason: :econnrefused}
Does anyone know how to solve this problem?
I believe you are getting this connection refused error when you are trying to access elasticsearch
from your webapp
.
Using localhost
inside a container refers to itself. In docker-compose, if you want to access another service which is listening in a particular port, then you have to frame your URL like http://<service-name>:<port>
In your case:
If you want to access elasticsearch
service which is listening on 9200
from webapp
container, then your URL should be http://elasticsearch:9200
In your webapp
service definition, for ELASTICSEARCH_URL
and ELASTICSEARCH_HOST
use elasticsearch
instead of localhost
.
Use the below compose file:
version: '3'
services:
registry:
restart: always
image: registry:2
ports:
- 443:443
volumes:
- /path/data:/var/lib/registry
- /path/certs:/registry/certs
- /path/auth:/registry/auth
webapp:
build:
context: ../../../
dockerfile: config/docker/dev/Dockerfile-dev
container_name: MyWebApp-dev
image: 'localhost:443/123'
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
- ELASTICSEARCH_HOST=elasticsearch
ports:
- "4000:4000"
- "3000:3000"
depends_on:
- db
- elasticsearch
- kibana
networks:
- esnet
db:
image: postgres:10
container_name: db
environment:
- POSTGRES_USER=paul
- POSTGRES_PASSWORD=SilviaZita1
- POSTGRES_DB=snitch_dev
networks:
- esnet
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
- 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
networks:
- esnet
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
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata02:/usr/share/elasticsearch/data
networks:
- esnet
kibana:
image: docker.elastic.co/kibana/kibana:7.0.1
ports:
- "5601:5601"
container_name: kibana
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
- ELASTICSEARCH_HOST=elasticsearch
depends_on:
- elasticsearch
networks:
- esnet
volumes:
esdata01:
driver: local
esdata02:
driver: local
networks:
esnet:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.