Skip to content

Instantly share code, notes, and snippets.

@rlunaro
Created March 22, 2021 22:34
Show Gist options
  • Save rlunaro/b67b7be7064be4dbc3b77033cf8102b7 to your computer and use it in GitHub Desktop.
Save rlunaro/b67b7be7064be4dbc3b77033cf8102b7 to your computer and use it in GitHub Desktop.
Dockerfile to create a couchdb database
#
# dockercouch.sh - helper script to manage the docker container for couch db
#
# It allows two commands: "--build" to build the container and "--run" to run the container
#
PROJECT_DIR=/YOUR-PROJECT-HERE
TAGNAME=superman_ha_muerto/couchdb
if [ "$1" != "--build" ] && [ "$1" != "--run" ]; then
echo "Incorrect option: $1"
echo "Usage: $0 [--build|--run]"
fi
#
# BUILD
#
if [ "$1" == "--build" ]; then
docker build -t $TAGNAME \
- << DOCKERFILE_HERE
#
#
#
FROM ubuntu:18.04
MAINTAINER superman_ha_muerto@yahoo.com
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -y update
RUN apt-get -y install apt-utils
RUN apt-get -y upgrade
RUN apt-get -y install curl gnupg ca-certificates
RUN apt-get -y install joe
# couchdb installation
RUN curl -L https://couchdb.apache.org/repo/bintray-pubkey.asc | apt-key add -
RUN echo "deb https://apache.bintray.com/couchdb-deb bionic main" > /etc/apt/sources.list.d/couchdb.list
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8756C4F765C9AC3CB6B85D62379CE192D401AB61
RUN apt-get update
RUN apt-get -y install couchdb
# couchdb setup
RUN cp /opt/couchdb/etc/default.ini /opt/couchdb/etc/default.ini.org
RUN cp /opt/couchdb/etc/local.ini /opt/couchdb/etc/local.ini.org
RUN cat /opt/couchdb/etc/default.ini.org | sed 's/bind_address.*/bind_address = 0.0.0.0/' > /opt/couchdb/etc/default.ini
RUN sed -e 's/;admin.*/admin = YOUR-PASSWORD-HERE/' /opt/couchdb/etc/local.ini.org > /opt/couchdb/etc/local.ini
CMD /usr/sbin/service couchdb start && /bin/bash
EXPOSE 5984/tcp
EXPOSE 5986/tcp
EXPOSE 6984/tcp
WORKDIR /data
VOLUME ["/data"]
DOCKERFILE_HERE
fi
#
# RUN
#
if [ "$1" == "--run" ]; then
# --user "$(id -u):$(id -g)"
# for debug, added "--rm" to not create a permanent container
docker run --rm \
--mount "type=bind,src=$PROJECT_DIR,dst=/src" \
--workdir /src \
--expose=5984-6984 \
-ti $TAGNAME
fi
@rlunaro
Copy link
Author

rlunaro commented Mar 22, 2021

This is a Dockerfile (indeed it's a script with a here document embedded which is the dockerfile itself) to create a ubuntu instance with a couchdb database.

To run it, just run "./dockercouch.sh --build" and after that "./dockercouch.sh --run" to start the database.

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