Docker Community Forums

Share and learn in the Docker community.

How to create a database in couchdb container using docker-compose.yml

I have a django webapp which stores data to couchdb table named “test”. dependency in django service is given as depends_on: couchserver.But django app terminates as it is unable to locate “test” table in couchdb. Below is the docker-compose.yml for couchdb (django is excluded here)

        image: couchdb
        command: curl -u rob:123456 -X PUT localhost:5984/test
          - "5984:5984"
          - COUCHDB_USER=rob
          - COUCHDB_PASSWORD=123456
          - ./data:/opt/couchdb/data

command: curl -u rob:123456 -X PUT localhost:5984/test
would not work and throws error because couchdb container has not started. I want to create a table in couchdb before the django app starts. How can i achieve this using docker-compose.yml or any other alternatives.

I’m novice to docker, any help is really appreciated.

Complete code with question :

Try to replace it with until [ $? -eq 0 ];do sleep 1; curl -u rob:123456 -X PUT localhost:5984/test; done.

If you want to do this in a “command” than this is the way, though you need to figure out find out what sort of quoting and/or wrapping it needs. maybee it need to be wrapped with something like bash -c '...'.

i have added to escape the ?. after building this is the error :

couchserver_1  | / line 106: exec: until: not found
y_couchserver_1 exited with code 127

I guess then you have to wait for someone actualy using that image…

Hope you eventualy find a solution!

Asked in stackoverflow got one reply to use an initializer but it fails because my django app starts before the initializer,
Here is the question with complete code :