Loading an existing `graph.db`/data folder with a Dockerfile

Hi, I'm able to build a Docker container for neo4j on a Ubuntu server that will be integrated with a broader set of services (linked through docker-compose), but I'm struggling trying to figure out how to include an existing graph.db file.

I'm using what I believe to be the basic Dockerfile for the Dockerhub neo4j image:

FROM openjdk:11-jdk-slim

ENV NEO4J_SHA256=63c85ee709916f9f5fa2fac7274f1a55bdd44d6ab353cbdd05f050aed9532e82 \
    NEO4J_TARBALL=neo4j-community-4.0.0-unix.tar.gz \
    NEO4J_EDITION=community \
    NEO4J_HOME="/var/lib/neo4j" \
    TINI_VERSION="v0.18.0" \
ARG NEO4J_URI=https://dist.neo4j.org/neo4j-community-4.0.0-unix.tar.gz

RUN addgroup --system neo4j && adduser --system --no-create-home --home "${NEO4J_HOME}" --ingroup neo4j neo4j

COPY ./local-package/* /tmp/
COPY ./data/* /tmp/data/

RUN apt update \
    && apt install -y curl wget gosu jq \
    && curl -L --fail --silent --show-error "https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini" > /sbin/tini \
    && echo "${TINI_SHA256}  /sbin/tini" | sha256sum -c --strict --quiet \
    && chmod +x /sbin/tini \
    && curl --fail --silent --show-error --location --remote-name ${NEO4J_URI} \
    && echo "${NEO4J_SHA256}  ${NEO4J_TARBALL}" | sha256sum -c --strict --quiet \
    && tar --extract --file ${NEO4J_TARBALL} --directory /var/lib \
    && mv /var/lib/neo4j-* "${NEO4J_HOME}" \
    && rm ${NEO4J_TARBALL} \
    && cp -r /tmp/data "${NEO4J_HOME}"/data \
    && mv /tmp/data /data \
    && mv "${NEO4J_HOME}"/logs /logs \
    && chown -R neo4j:neo4j /data \
    && chmod -R 777 /data \
    && chown -R neo4j:neo4j /logs \
    && chmod -R 777 /logs \
    && chown -R neo4j:neo4j "${NEO4J_HOME}" \
    && chmod -R 777 "${NEO4J_HOME}" \
    && ln -s /logs "${NEO4J_HOME}"/logs \
    && mv /tmp/neo4jlabs-plugins.json /neo4jlabs-plugins.json \
    && rm -rf /tmp/* \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get -y purge --auto-remove curl



VOLUME /data /logs

COPY docker-entrypoint.sh /docker-entrypoint.sh

EXPOSE 7474 7473 7687

ENTRYPOINT ["/sbin/tini", "-g", "--", "/docker-entrypoint.sh"]
CMD ["neo4j"]

But it's not clear to me what I need to modify to allow access to an existing database that can persist outside of the container (it currently contains ~2 gigs of data, and should be available even when I close the container).

Any help would be appreciated!

If you use the standard neo4j docker image you just volume mount the /data using -v. Underneath /data/database/<mydbname> you'll find the internal store data. In 3.5 the default db name is graph.db.

Out of curiousity: why are you trying to build your own docker container and not just use the official one?

I think I actually understand hwat's happening a bit better thanks to your response. I should keep the Dockerfile as is, but mount the graph.db file volume in the docker-compose.yaml. Is that correct?

Mostly. The recommended way is to mount /data volume.

1 Like