Skip to content

Instantly share code, notes, and snippets.

@mqtik
Last active May 12, 2021 02:34
Show Gist options
  • Save mqtik/76e92eff4580044f92d6bcf715c38182 to your computer and use it in GitHub Desktop.
Save mqtik/76e92eff4580044f92d6bcf715c38182 to your computer and use it in GitHub Desktop.
Set up server with Docker and CouchDB

Installing Docker

Let's install Docker and set it to be from their repository instead of Ubuntu (which comes by default). Also, let's disable root mode in order to run Docker.

sudo apt install apt-transport-https ca-certificates curl software-properties-common && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic test" && sudo apt update && sudo apt install docker-ce

To save money and not run each instance of CouchDB by servers, let's create instances for each project. And define and admin & password (since CouchDB doesn't) Remove -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password if you want to start CouchDB as admin party default.

Now, let's install CouchDB docker run -d --name mQserv couchdb

Or with more parameters: docker run --name mQdb --restart=always -p 80:5984 --link mQserv:couch couchdb -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password (restart: always, listen on port 80 proxying default 5984 of couch) Run: docker run -p 5984:5984 -d couchdb

As you work with Docker, however, it’s also easy to accumulate an excessive number of unused images, containers, and data volumes that clutter the output and consume disk space.

docker system prune To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:

docker system prune -a

@mqtik
Copy link
Author

mqtik commented May 17, 2020

Publicfields
image

@mqtik
Copy link
Author

mqtik commented May 12, 2021

version: '3'
services:
couchserver:
image: "couchdb:3.1.1"

ports:
  - "5984:5984"
environment:
  - COUCHDB_USER=user
  - COUCHDB_PASSWORD=pass
volumes: 
  - ./dbdata:/opt/couchdb/data
  - ./dbdata:/opt/couchdb/etc/local.d

initializer:
image: curlimages/curl
deploy:
restart_policy:
condition: on-failure
depends_on:
- couchserver
command: ["sh","-c","sleep 15 && curl -u newton:pass-X PUT couchserver:5984/_users && curl -u user:pass-X PUT couchserver:5984/test"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment