0

I am trying to deploy a Mongodb docker container on Bluemix w/ data persistence but always getting the error when the system is trying to mount on the container "/data/db" on the host (Bluemix) volume and the container doesn't start. For the last 2 days, I have researched and tried multiple options, including one for Postgres on stackoverflow, but still getting the same error. Any help would be greatly appreciated.

Error: $ docker logs f450993a-4cc ;chown: changing ownership of '/data/db': Permission denied

docker-compose file:

docker-compose.yml

 mongodb:
  container_name: mymongo
  image: registry.ng.bluemix.net/helpfull/mongo:3.2.10
  volumes:
    - mongodb:/data/db:rw
  ports:
    - "27017"
Community
  • 1
  • 1
Nauman
  • 1
  • 1
  • The answer in the link you provided for the Postgres question is the way to go. I've never tried that with docker-compose.yml though, but this is also what is documented here https://console.ng.bluemix.net/docs/containers/container_troubleshoot.html#ts_vol_owner – Alex da Silva Mar 09 '17 at 14:00

1 Answers1

0

Thank you Israel.Zinc for the nice editing of the question and Alex for your suggestion. After playing little bit more with the script based on the previous post about Redis solution by krsyoung, I was able to make it work in the following way. I am new to Docker/Bluemix so not sure if this is the right solution but it is working fine and I hope it will save time for some other people.

Docker-compose:

mongo:
  container_name: hfmongo
  image: registry.ng.bluemix.net/helpfull/hfmongo:3.4.2
  volumes:
    - mongodatabase:/data/db
  ports:
    - "27017"

Dockerfile:

FROM mongo:3.4

COPY docker-entrypoint-bluemix.sh /
ENTRYPOINT ["/docker-entrypoint-bluemix.sh"]

EXPOSE 27017
CMD ["mongod"]

docker-entrypoint-bluemix.sh

#!/bin/bash
set -e
set -x

if [ "${1:0:1}" = '-' ]; then
  set -- mongod "$@"
fi

if [[ "$1" == mongo* ]] && [ "$(id -u)" = '0' ]; then
    STARTTIME=$(date +%s)
    echo "START: hack for IBM Bluemix"
    chmod 775 "/data/db"
    adduser mongodb root
    echo "END: hack for IBM Bluemix"
    exec gosu mongodb "$BASH_SOURCE" "$@"
fi
exec "$@"
Community
  • 1
  • 1
Nauman
  • 1
  • 1
  • Is this working for you? I'm trying your approach and seeing the container Shutdown with empty logs. – jamesism Apr 20 '17 at 15:05