Reputation: 113
I am running MacOSX 10.11 and I recently tried to dockerize all my projects.
I have an issue trying to run a mongoDB + NodeJS application using docker-compose.
Here is my docker-compose script :
version: '2'
services:
mongodata:
image: mongo:latest
volumes:
- "${APP_DB}:/data"
command: "--break-mongo"
mongo-app:
image: mongo:latest
volumes_from:
- "mongodata"
expose:
- "27017"
ports:
- "27017:27017"
command: "--smallfiles --dbpath /data"
web:
build: .
volumes:
- .:/usr/src/app
ports:
- "3000:3000"
depends_on:
- mongo-app
links:
- mongo-app
environment:
- PORT=3000
So basically I have a volume-only container which will persist my files. Then I run mongo based on that volume then I run my NodeJS app.
But everytime I try tto run docker-compose up, I have the following error :
mongo-app_1 | 2016-04-22T07:14:05.931+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data 64-bit host=4c43c9e20014
mongo-app_1 | 2016-04-22T07:14:05.931+0000 I CONTROL [initandlisten] db version v3.2.5
mongodata_1 | try 'mongod --help' for more information
mongo-app_1 | 2016-04-22T07:14:05.932+0000 I CONTROL [initandlisten] git version: 34e65e5383f7ea1726332cb175b73077ec4a1b02
mongo-app_1 | 2016-04-22T07:14:05.932+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
mongo-app_1 | 2016-04-22T07:14:05.932+0000 I CONTROL [initandlisten] allocator: tcmalloc
mongo-app_1 | 2016-04-22T07:14:05.932+0000 I CONTROL [initandlisten] modules: none
mongo-app_1 | 2016-04-22T07:14:05.933+0000 I CONTROL [initandlisten] build environment:
mongo-app_1 | 2016-04-22T07:14:05.933+0000 I CONTROL [initandlisten] distmod: debian71
mongo-app_1 | 2016-04-22T07:14:05.933+0000 I CONTROL [initandlisten] distarch: x86_64
mongo-app_1 | 2016-04-22T07:14:05.933+0000 I CONTROL [initandlisten] target_arch: x86_64
mongo-app_1 | 2016-04-22T07:14:05.934+0000 I CONTROL [initandlisten] options: { storage: { dbPath: "/data", mmapv1: { smallFiles: true } } }
mongo-app_1 | 2016-04-22T07:14:05.947+0000 I - [initandlisten] Detected data files in /data created by the 'mmapv1' storage engine, so setting the active storage engine to 'mmapv1'.
mongo-app_1 | 2016-04-22T07:14:05.958+0000 W - [initandlisten] Detected unclean shutdown - /data/mongod.lock is not empty.
mongo-app_1 | 2016-04-22T07:14:05.959+0000 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
mongo-app_1 | 2016-04-22T07:14:05.964+0000 I CONTROL [initandlisten] dbexit: rc: 100
As far as I know it's happening on MacOSX only, I tried to CHOWN + CHMOD the /data folder but I saw a thread that says that you can't CHOWN in a container once the volume has been mounted and I can confirm that it does nothing. But since I am using a docker-compose file, I can't do that BEFORE mounting the volume. Do you have an idea ?
Upvotes: 2
Views: 2378
Reputation: 2211
Do you actually need to mount the data directory from your host system? Can't you just use container volumes for the data folder?
The information will still be persisted on the container.
Example:
version: '2'
volumes:
mongo_data: {}
services:
mongo-app:
image: mongo:latest
volumes:
- mongo_data:/data/db
expose:
- "27017"
ports:
- "27017:27017"
command: "--smallfiles --dbpath /data/db"
Sources:
Upvotes: 1
Reputation: 4907
Using docker-machine on MacOS you can bind volumes only inside home host directory. Other directories don't work because they are not in folder that shared by VBox. You can share your folder outside user home using VBoxManage
:
https://www.virtualbox.org/manual/ch08.html#vboxmanage-sharedfolder
More info about this issue:
https://github.com/docker/machine/issues/1826
Upvotes: 1