I have a webapp written in django which i need to connect with couchdb both are running on docker container. django will store the data in couchdb table named "test". So i need to create "test" table in couch db. But i'm unable to figure out how to achieve this as there is no good material available for reference. I have tried the below codes but it is throwing the following error because couchdb is not up and running. Is there any way to create a table in couchdb using docker-compose.yml or any other alternatives.
I use docker-compose up to run the containers
docker-compose.yml
version: '3'
services:
web:
build: .
command: python ./webapp/server.py
volumes:
- .:/code
- ./webapp/static:/static
networks:
- couchserver_network
depends_on:
- couchserver
couchserver:
image: couchdb
ports:
- "5984:5984"
command: curl -u rob:123456 -X PUT localhost:5984/_users && curl -u rob:123456 -X PUT localhost:5984/test
environment:
- COUCHDB_USER=rob
- COUCHDB_PASSWORD=123456
volumes:
- ./dbdata:/opt/couchdb/data
networks:
- couchserver_network
networks:
couchserver_network:
driver: bridge
Error thrown :
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to localhost port 5984: Connection refused
If i remove the line "command: curl -u rob:123456 -X PUT localhost:5984/_users && curl -u rob:123456 -X PUT localhost:5984/test" below error is thrown :
couchserver_1 | {database_does_not_exist,[{mem3_shards,load_shards_from_db,"_users",[{file,"src/mem3_shards.erl"},{line,399}]},....
This is my Dockerfile :
FROM python:3.6-slim-buster
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
Any sort of help is really appreciated
One more query : what does the below lines do. I'm novice into docker and this is my first hands on with it
volumes:
- ./dbdata:/opt/couchdb/data