So I have 1 docker container named elastic which has 2 images, one for elastic search and one for kibana. This is the yml file that creates them
version: '3.1'
services:
elasticsearch:
container_name: els
image: docker.elastic.co/elasticsearch/elasticsearch:7.16.1
ports:
- 9200:9200
volumes:
- elasticsearch-data:/usr/share/elasticsearch/datafile
environment:
- xpack.monitoring.enabled=true
- xpack.watcher.enabled=false
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.type=single-node
networks:
- elasticnetwork
kibana:
container_name: kibana
image: docker.elastic.co/kibana/kibana:7.16.1
ports:
- 5601:4601
depends_on:
- elasticsearch
environment:
- ELASTICSEARCH_URL=http://localhost:9200
networks:
- elasticnetwork
networks:
elasticnetwork:
driver: bridge
volumes:
elasticsearch-data:
As you can see I'm working with localhost and default ports. Then I run a mongo DB that I only use inside MongoDB Compass to connect via localhost:27017 without an image and without using a docker container.
The issue is the following: I configured a monstache file that synchs data from a collection named Concerts to an index in elasticsearh. It works fine when I execute the command inside the console. This is the monstache file:
mongo-url = "mongodb://localhost:27017"
elasticsearch-urls = ["http://localhost:9200"]
elasticsearch-max-conns = 10
replay = false
resume = true
enable-oplog = true
resume-name = "default"
namespace-regex = '^.Test\.Concert$' # my namespace which I want to sync
direct-read-namespaces = ["Test.Concert"] # directly copy entire data to es from this name space
index-as-update = true # upsert docs
verbose = true # logs enabled
exit-after-direct-reads = false # don’t exit after copying from db to es
[[mapping]]
namespace = "Test.Concert" # my db collection from where I want to sync
index = "Concert" # my index where I want to sync data.
This is how I create the image
# Build monstahce plugin
FROM rwynn/monstache-builder-cache-rel6:1.0.3 AS builder
RUN git clone https://github.com/rwynn/monstache.git/app && \
cd /app && \
git checkout v6.4.3 && \
go mod download
WORKDIR /app/docker/plugin
RUN go mod download
# Main container
FROM rwynn/monstache:6.4.3
WORKDIR /app
COPY monstache.toml monstache.config.toml
ENTRYPOINT [ "/bin/monstache", "-f", "monstache.config.toml" ]
So I tried to create an image inside docker that executes that command continuously but it throws the error Unable to connect to MongoDB using URL mongodb://localhost:27017: server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: localhost:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : dial tcp 127.0.0.1:27017: connect: connection refused }, ] }
This confuses me since the command and configuration work fine and the data gets synched. However, when I create the image it stops running after a few seconds because it can't connect to MongoDB. Is there a missing configuration so that the localhost can be reached? Or are there other alternatives to run the monstache command without an image and actively listen to my changes in one collection?