Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mongodb startup problem with simple dockerfile #489

Closed
stephanosbacon opened this issue Mar 13, 2017 · 5 comments
Closed

mongodb startup problem with simple dockerfile #489

stephanosbacon opened this issue Mar 13, 2017 · 5 comments

Comments

@stephanosbacon
Copy link

The following dockerfile:

version: '2'
services:
mongo:
image: "mongo"
ports:
- "27017:27017"

when processed with:

kompose convert -f docker-compose.yml --provider OpenShift

will generate mongo-imagestream, mongo-deploymentconfig and mongo-service, which, when deployed to OpenShift (Minishift in this case) as follows:

oc create -f mongo-imagestream.yaml
oc create -f mongo-deploymentconfig.yaml
oc create -f mongo-service.yaml

will result in mongodb not starting with the following log [1]

However, if I say "oc new-app --docker-image=mongo" mongo starts up without a problem.

[1] The log:

2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=cablegram-1-b1zua
2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] db version v3.4.2
2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t 3 May 2016
2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] allocator: tcmalloc
2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] modules: none
2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] build environment:
2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] distmod: debian81
2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] distarch: x86_64
2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] target_arch: x86_64
2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] options: {}
2017-03-13T17:26:40.695+0000 I STORAGE [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
2017-03-13T17:26:40.695+0000 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-03-13T17:26:40.695+0000 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] now exiting
2017-03-13T17:26:40.695+0000 I CONTROL [initandlisten] shutting down with code:100

@procrypt
Copy link

@stephanosbacon You are getting this error because you are trying to run an application which requires root privilege to inside the container. OpenShift by default, does not allow the container to run using UID 0. I tried the application using oc new-app --docker-image=mongo and got the same error. You need to set the cluster policy to allow containers running with UID 0.
Run containers with root in OpenShift.

@stephanosbacon
Copy link
Author

Actually, it works for me with oc new-app.. I'm using minishift by the way.

@kadel
Copy link
Member

kadel commented Mar 14, 2017

problem is with volumes.

mongo image is using two volumes /data/db and /data/configdb

oc new-app is a bit smarter than kompose, it inspects image, detects docker volumes and creates kubernetes volumes that are non-persistant and host-local (aka. emptyDir)

with Kompose volumes have to be defined explicitly.

version: '2'

services:
  mongo:
    image: "mongo"
    ports:
      - "27017:27017"
    volumes:
      - /data/db
      - /data/configdb

If you want deploy this to minishift (or any other cluster that doesn't support PersistentVolumes) you have to add --emptyvol option. This will do exactly same think that oc new-app does.

./kompose --provider openshift convert --emptyvols

For cluster with PersistentVolumes or with storage auto-provisioning setup you can omit --emptyvols. Than Kompose will create regular PersistentVolumeClams and mongo data will be persistent even if mongo pods gets restarted and moved to another machine.

▶ ./kompose --provider openshift convert                                                                  
INFO file "mongo-service.yaml" created            
INFO file "mongo-deploymentconfig.yaml" created   
INFO file "mongo-imagestream.yaml" created        
INFO file "mongo-claim0-persistentvolumeclaim.yaml" created 
INFO file "mongo-claim1-persistentvolumeclaim.yaml" created

@stephanosbacon
Copy link
Author

Thanks!

@kadel
Copy link
Member

kadel commented Apr 26, 2017

i think we can close this

@kadel kadel closed this as completed Apr 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants