Tom M
Tom M

Reputation: 2904

Can't add persistent folder to bitnami/mongodb on windows

I think this might be related to file system incompatibility (nfts/ext*)

How can I compose my containers and persist the db without the container exiting?

I'm using the bitnami-mongodb-image

Error:

Error executing 'postInstallation': EACCES: permission denied, mkdir '/bitnami/mongodb'
mongodb_1 exited with code 1

Full Output:

Recreating mongodb_1 ... done
Starting node_1      ... done
Attaching to node_1, mongodb_1
mongodb_1  |
mongodb_1  | Welcome to the Bitnami mongodb container
mongodb_1  | Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-mongodb
mongodb_1  | Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-mongodb/issues
mongodb_1  |
mongodb_1  | nami    INFO  Initializing mongodb
mongodb_1  | mongodb INFO  ==> Deploying MongoDB from scratch...
mongodb_1  | Error executing 'postInstallation': EACCES: permission denied, mkdir '/bitnami/mongodb'
mongodb_1 exited with code 1

Docker Version:

Docker version 18.06.0-ce, build 0ffa825

Windows Version:

Microsoft Windows 10 Pro
Version 10.0.17134 Build 17134

This is my docker-compose.yml so far:

version: "2"
services:
  node:
    image: "node:alpine"
    user: "node"
    working_dir: /home/node/app
    environment:
    - NODE_ENV=development
    volumes:
    - ./:/home/node/app
    ports:
    - "8888:8888"
    command: "tail -f /dev/null"
  mongodb:
    image: 'bitnami/mongodb'
    ports:
    - "27017:27017"
    volumes:
    - "./data/db:/bitnami"
    - "./conf/mongo:/opt/bitnami/mongodb/conf"

Upvotes: 4

Views: 3520

Answers (1)

Bizmate
Bizmate

Reputation: 1872

I do not use Windows but you can definitely try to use a named volume and see if the permission problem goes away

version: "2"
services:
  node:
    image: "node:alpine"
    user: "node"
    working_dir: /home/node/app
    environment:
    - NODE_ENV=development
    volumes:
    - ./:/home/node/app
    ports:
    - "8888:8888"
    command: "tail -f /dev/null"
  mongodb:
    image: 'bitnami/mongodb'
    ports:
    - "27017:27017"
    volumes:
    - mongodata:/bitnami:rw
    - "./conf/mongo:/opt/bitnami/mongodb/conf"
volumes:
  mongodata:

I would like to stress this is a named volume, compared to the host volumes you are using. It is the best option for production and you need to be aware that docker will manage and store the files for you so you will not see the files in your project folder.

If you still want to use host volumes (so volumes that write to that location you specify in your project subfolder on the host machine) you need to apply a permission fix, here is an example for mariadb but it will work for mongo too

https://github.com/bitnami/bitnami-docker-mariadb/issues/136#issuecomment-354644226

In short, you need to know what is the user of the filesystem (in the example 1001 is the user id on my host machine for my logged in user) on your host and then chown that folder to this user so the user will be the same on the folder and your host system.

A full example:

version: "2"
services:
  fix-mongodb-permissions:
    image: 'bitnami/mongodb:latest'
    user: root
    command: chown -R 1001:1001 /bitnami
    volumes:
      - "./data:/bitnami"
  mongodb:
    image: 'bitnami/mongodb'
    ports:
      - "27017:27017"
    volumes:
      - ./data:/bitnami:rw
    depends_on:
      - fix-mongodb-permissions

I hope this helps

Upvotes: 8

Related Questions