I have been having problems using mongodb as a service in docker-compose. I managed to insert data into its container (csv, txt and json files, for instance) at data/db/ through a volume folder, but I still cant use it as a collection. I believe I should use the function mongoimport`, but it fails to connect to the host. All seems to be fine but the host. I have tried a lot of other addresses as hosts, but none have worked.
Below is my docker-compose.yml
version: '3'
services:
mongodb:
image: mongo:3.6
container_name: mongodb
restart: on-failure
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=example
volumes:
- ./mongodbvol:/data/db
ports:
- "27107:27107"
command:
mongoimport --host http://0.0.0.0:27017 -c col1 --type csv --file /data/db/tt.csv --headerline
mongo-express:
image: mongo-express
container_name: mongo-express
restart: on-failure
environment:
- ME_CONFIG_MONGODB_SERVER=mongodb
- ME_CONFIG_MONGODB_ADMINUSERNAME=root
- ME_CONFIG_MONGODB_ADMINPASSWORD=example
- ME_CONFIG_BASICAUTH_USERNAME=necode
- ME_CONFIG_BASICAUTH_PASSWORD=passwd
ports:
- "8081:8081"
depends_on:
- mongodb
rshiny:
image: guigo13/app
container_name: rshiny
restart: on-failure
command: R -e "shiny::runApp('R/app.R', host = '0.0.0.0', port = 3838)"
environment:
- DB_URI=mongodb
- DB_USERNAME=root
- DB_PASSWORD=example
- DB_NAME=appdb
- DB_HOST=mongodb
- DB_PORT=27017
ports:
- "3838:3838"
- "3839:3838"
depends_on:
- mongodb
and here is the error from the logs
mongodb | 2021-10-29T02:51:09.170+0000 [########################] test.col1 11B/11B (100.0%)
mongodb | 2021-10-29T02:51:09.685+0000 [########################] test.col1 11B/11B (100.0%)
mongodb | 2021-10-29T02:51:09.685+0000 Failed: error connecting to db server: no reachable servers
mongodb | 2021-10-29T02:51:09.685+0000 imported 0 documents
Could someone, please, get me an alternative? Thanks in advance.