4

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"
Tom M
  • 2,815
  • 2
  • 20
  • 47

1 Answers1

8

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

Bizmate
  • 1,835
  • 1
  • 15
  • 19
  • Thank you for your answer - is it possible to retrieve/backup the data from the named volume at some point? My guess is that the data volume is floating around somewhere inside the VM running the engine. – Tom M Aug 21 '18 at 08:10
  • The `debian-9` bitnami/mongodb tag is using user 1001. https://github.com/bitnami/bitnami-docker-mongodb/blob/master/4.1/debian-9/Dockerfile – bluescores Aug 21 '18 at 12:56
  • 1
    @bluescores the files need to be accessed using the same user so the mount needs to be mapped to the local user that has access and rights to the underlying host files. tom about accessing the files yes you can and it depends on the OS, on Windows i suggest checking out this answer https://stackoverflow.com/a/43182885/1058226 – Bizmate Aug 21 '18 at 13:31