Skip to content

Commit

Permalink
FAB-5700 Couchdb crashes with mounted volume
Browse files Browse the repository at this point in the history
The CouchDB image has a volume at
/opt/couchdb/data which it uses to
store it's persistent data.  If you
try to attach an external volume for this
and either the host path does not exist or
the permissions for the host path are
incorrect, CouchDB will crash and the
container will fail to start.

This comes down to a permissions issue
coupled with "helpful" behavior from
the Docker daemon.

The issue is that if the host path does not
exist, the Docker daemon will create the host
path but will create it under the same user
as the daemon is running (which is typically
root).  The current Dockerfile then changes
the user to couchdb but now which then
runs all subsequent commands as couchdb.
Although a volume is created after this,
permissions are not / cannot be
properly set.

So this fix removes the use of the
USER command in the Dockerfile,
changes ownership of the volume
in the docker-entrypoint script
and then finally uses su-exec to
start CouchDB as the couchdb user

Change-Id: If8ac0e34b13d447d68b99408cebcfbf93d257c0f
Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
  • Loading branch information
mastersingh24 committed Sep 30, 2017
1 parent 8929b24 commit 3b4d8bf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 0 additions & 2 deletions images/couchdb/Dockerfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ RUN chmod +x /docker-entrypoint.sh \
WORKDIR /opt/couchdb
EXPOSE 5984 4369 9100

USER couchdb

VOLUME ["/opt/couchdb/data"]

ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
Expand Down
4 changes: 3 additions & 1 deletion images/couchdb/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
sleep 1
fi

exec "$@"
chown -R couchdb:couchdb /opt/couchdb/data

su-exec couchdb "$@"

0 comments on commit 3b4d8bf

Please sign in to comment.