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 does docker image size impact runtime characteristics?
  • Dokku showing errors in console
  • Equivalent of local host files for running Bluemix containers
  • Why does AWS have two services to deploy Docker (one “Infra” and one “Platform”)?
  • Self-hosted alternative to hub.docker.com?
  • How to optimize performance for a docker container?
  • Keeping build directories consistent with a docker container that ignores test dir while compiling from typescript
  • how can I open a flask app on my browser that's running remotely on docker?
  • Dynamic DNS Resolution with HAProxy and Docker
  • Image Name, Container Name in Docker Syslog Tag in Docker-Compose
  • Launching run docker from cloud-init incorrectly prefixes “docker.io” to image name
  • I lose my data when the container exits
  • 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.