Docker Community Forums

Share and learn in the Docker community.

Docker application container is creating empty db when connecting with window system mongodb database

docker

(Nitikishu) #1

Hi,

I am trying to run my application in docker container. When I connect with my system db using docker-compose it is not connecting with existing db data. rather than it is creating same db with empty collection. and also deleting existing collection on the same db which is exists in my system.

For example: I am having sample_db in my system. I am using that db to run and connect with the application. mongoose.connect(“mongodb://mongo:27017/sample_db”) .
In my sample_db I have lots of collection. when I try to connect and run in docker-machine docker-compose up -d --build command application is running in docker-machine ip with allocated port(192.168.99.100:4200) my application has register page.

when I enter all details to click register button it should store into app_users collection. But it is not storing in to collection. I checked my system db. in that also all existing app_users data are get deleted. Even when I enter the data manually in db. application is not responding.

Why it is deleting window system database existing collections. Why it is not storing data into database


(Sam) #2

can u show us more of the application container startup…

what does it do?


(Nitikishu) #3

This is my project code… My project is running on 192.168.99.100:4500. when I register button it is not storing data into db. but it is creating empty db…

my dbname is testdb. in that testdb only one collection is created when I run the applicaiton: that is session. If register it is not saving data into that testdb. so, I tried another way like manually created one collection like app_users, app_roles… app_users is the collection which store the registered user details . app_roles is the name which user is allowed to login.(it has userneme and password). using that username and password application is
not opening


(Sam) #4

can we see the compose file and any dockerfiles…


(Nitikishu) #5

yes. Here I shared dockerfile and docker-compose file:

Docker-Compose

version : '3’
services :
sampledocker:
build: .
ports:
- "4500:4200"
depends_on:
- mongo
simple:
build: .
ports:
- "2000:3000"
depends_on:
- mongo
mongo:
image: mongo:3.4.2
ports:
- "27017:27017"
volumes:
- data:/data/db
volumes:
data:

DockerFile

FROM node:latest
RUN mkdir -p C:\Users\user2\Sample
WORKDIR C:\Users\user2\Sample
COPY package.json C:\Users\user2\Sample
RUN npm install
COPY . .
EXPOSE 4200
CMD [ “npm”, “start” ]


(Nitikishu) #6

I am using passport.js for login credentials purpose is there any problem with that. Because I am unable to register . once I click the register button the data should save in to db. I have created one sample in that data is stored into db. but in my application data is not saved into db. I already shared my project files. can you say the mistake to resolve this type of problem


(Sam) #7

there is a note in the mongodb image docs here https://hub.docker.com/_/mongo/

that says

WARNING (Windows & OS X): The default Docker setup on Windows and OS X uses a VirtualBox VM to host the Docker daemon. Unfortunately, the mechanism VirtualBox uses to share folders between the host system and the Docker container is not compatible with the memory mapped files used by MongoDB (see vbox bug, docs.mongodb.org and related jira.mongodb.org bug). This means that it is not possible to run a MongoDB container with the data directory mapped to the host.

i think this means that mongo does not see the original database stored on the volume


(Nitikishu) #8

how to resolve this problem. Then using windows system we cannot run application with mongodb?


(Nitikishu) #9

@sdetweil, I have created one sample application to store the data into mongodb. That project is working well, I can insert and see the inserted data in my database. Then why the above project is not work?


(Nitikishu) #10

can you say that line clearly, reading that line I cant get clearly. what I understood is it will not connect with my mongodb databse. is that correct? If So, I have a sample application to store the data into mongodb then how it is storing?


(Sam) #11

i do not know. something in docker compose I think… i do not use docker compose.


(Nitikishu) #12

using docker compose only i just created and store data in to my db.


(Sam) #13

what is different about this compose file vs the 1st one?


(Nitikishu) #14

in this compose file I am using/running two application with mongo image, Even If I try to access one application it wont work.


(Nitikishu) #15

This is my simpleNodeApp. In this just i am storing data into db. using compose file only. It is working fine.


(Sam) #16

so, maybe its in the app code of the other solution


(Nitikishu) #17

is there any solution to resolve? Because I am facing this problem very long time.


(Sam) #18

‘other solution’ means your other application. the compose files look similar… so if not compose, then maybe application code…


(Nitikishu) #19

I am using passport js, cookies,session only


(Sam) #20

sorry, i don’t know any of that technology