Dockerfile for adding volumes to a gerrit container

FROM ubuntu:trusty



ENV GERRIT_USER gerrit2
ENV GERRIT_HOME /home/${GERRIT_USER}
ENV GERRIT_SITE ${GERRIT_HOME}/gerrit/site
ENV GERRIT_WAR ${GERRIT_HOME}/gerrit.war
ENV GERRIT_VERSION 2.9.3
RUN useradd -m ${GERRIT_USER}

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y openjdk-7-jre-headless git-core vim

ADD https://gerrit-releases.storage.googleapis.com/gerrit-${GERRIT_VERSION}.war /tmp/gerrit.war
ADD . /app

RUN mv /tmp/gerrit.war $GERRIT_WAR
RUN chown -R ${GERRIT_USER}:${GERRIT_USER} $GERRIT_HOME

USER $GERRIT_USER
WORKDIR $GERRIT_HOME

RUN mkdir -p $GERRIT_SITE
RUN chown -R ${GERRIT_USER}:${GERRIT_USER} $GERRIT_SITE

ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64/jre
RUN java -jar $GERRIT_WAR init --batch -d ${GERRIT_HOME}/gerrit

ADD gerrit.config $GERRIT_HOME/gerrit/etc/gerrit.config

VOLUME $GERRIT_SITE

ENV AUTH_TYPE LDAP

EXPOSE 8080 29418
CMD ["/app/start.sh"]

Context:
Most of the above dockerfile is what I got off of dockerhub for running gerrit in a container using dockers. The changes I have done is to set GERRIT_SITE, create this directory, allot permission for GERRIT_USER to use this directory and set it as a volume. When I build the docker image, the docker image is successfully built. But, when I try running the container, mounting my host volume to the docker container volume I get the following error…

-bash-4.1$ docker run -p 8080:8080 -p 29418:29418 -v /home/user/gerritVolume/vols:/home/gerrit2/gerrit/site gerritvol

** ERROR: Gerrit is not initialized in /home/gerrit2/gerrit/site
cat: /home/gerrit2/gerrit/logs/error_log: No such file or directory

I made sure the host directory exists with all permissions. I have been stuck on this and am not sure how to go about this. I some help. Thank you in advance.

  • How can I fix 'No space left on device' error in Docker?
  • bash syntax error while running docker command
  • How to pass command line arguments to a docker image
  • How to stop/relaunch docker container without losing the changes?
  • How to set docker-machine env for fabric local() commands
  • How to mount a single file in a volume
  • REPLICAS remains 0 after running `docker stack deploy` command in manager machine
  • Temporary failure in name resolution [Errno -3] with Docker
  • Docker GELF logging additional fields
  • How to run docker builds from Jenkins on a Mac?
  • CentOs 7 : Docker -d “Error running deviceCreate (CreatePool)”
  • Docker DNS Not Seeing External Servers
  • One Solution collect form web for “Dockerfile for adding volumes to a gerrit container”

    By bind-mounting a directory from your host, the files on the host take precedence, so the /home/gerrit2/gerrit/site directory inside the container will be empty, unless you have an existing site on your host, that you’re bind-mounting in the container.

    I don’t have experience with running Gerrit, but according to this line; https://code.google.com/p/gerrit/source/browse/gerrit-pgm/src/main/resources/com/google/gerrit/pgm/gerrit.sh?r=967eae196f5433394cdc5e63fe4d154ef458bb39#164

    It looks like gerrit checks if the site-files are present in that directory, and if not, produce the error.

    Does the container run correctly if you don’t use the -v option when starting the container?

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.