Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

487
Visualizações
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...

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda