• Home
  • Jobs
  • Courses
  • Teachers
  • For business
  • Blog
  • ES/EN

0

16
Views
Running MongoDb on local Docker/Kubernets install, mounting disk local doesn't work

I'm trying to run this, after creating the folder \data\MongoDb\database and sharing it with everyone (Windows 10 doesn't seem to want to share with localsystem, but that should work anyway)

It crashes trying to Create the container with a 'Create Container error' I think that somehow I've specified the mapping on how to mount the claim - I'm trying for /data/db which I've confirmed there is data there if I remove the 'volumeMounts' part at the bottom - but if I don't have that, then how does it know that is where I want it mounted? It appears to not mount that folder if I don't add that, and the server works fine in that case, but of course, it has the data inside the server and when it gets powered down and back up POOF! goes your data.

Here is the YAML file I'm using

apiVersion: v1
kind: Service
metadata:
  name: mongodb
  labels:
    app: mongodb
spec:
  ports:
    - port: 27017
      targetPort: 27017
  selector:
    app: mongodb
  type: LoadBalancer
  externalIPs:
    - 192.168.1.9
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mongo-storage
  labels:
    type: local
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: manual
  hostPath:
    path: c:/data/mongodb/database
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-mongo-storage
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: manual
  resources:
    requests:
      storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb
  labels:
    app: mongodb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels:
        app: mongodb
    spec:
        containers:
        - name: mongo2
          image: mongo
          ports:
          - containerPort: 27017
            name: mongodb
          env:
          - name: MONGO_INITDB_ROOT_USERNAME
            value: xxx
          - name: MONGO_INITDB_ROOT_PASSWORD
            value: xxxx
          - name: MONGO_INITDB_DATABASE
            value: defaultDatabase    
          volumeMounts:
            - mountPath: "/data/db"
              name: mongo-storage            
        volumes:
            - name: mongo-storage
              persistentVolumeClaim:
                claimName: pv-mongo-storage
            

I would presume that there is also some vastly better way to set the password in the MongoDb Container too... This is the only way I've see that worked so far... Oh, I also tried the mountPath without the " around it, because 1. that makes more sense to me, and 2 some of the examples did it that way... No luck

The error I'm getting is 'invalid mode: /data/db' - which would imply that the image can't mount that folder because it has the wrong mode... On the other hand, is it because the host is Windows?

I don't know... I would hope that it can mount it under Windows...

7 days ago ·

Santiago Trujillo

1 answers
Answer question

0

Adding this from comments so it will be visible to a community.

Docker Desktop for Windows provides an ability to access Windows files/directories from Docker containers. The windows directories are mounted in a docker container in /run/desktop/mnt/host/ dir.

So, you should specify the path to your db directory on Windows (c:/data/mongodb/database) host as:

/run/desktop/mnt/host/c/data/mongodb/database

This is only specific to Docker Desktop for Windows.

7 days ago · Santiago Trujillo Report
Answer question
Remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Startups
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.