Config file for Neo4j Docker Image - macos

I installed neo4j-3.0 as a docker image in Mac OSX. Where can I locate the config file for neo4j ?

They have a dedicated section on their page for that ...
There are 3 ways: via environment variables, mounting a /conf volume and building a new image
The /conf volume is probably the way the OP wants:
To make arbitrary modifications to the Neo4j configuration, provide
the container with a /conf volume.
docker run \
--detach \
--publish=7474:7474 --publish=7687:7687 \
--volume=$HOME/neo4j/data:/data \
--volume=$HOME/neo4j/logs:/logs \
--volume=$HOME/neo4j/conf:/conf \
neo4j:3.1
Any configuration files in the /conf volume will override files
provided by the image. This includes values that may have been set in
response to environment variables passed to the container by Docker.
So if you want to change one value in a file you must ensure that the
rest of the file is complete and correct.
To dump an initial set of configuration files, run the image with the
dump-config command.
docker run --rm\
--volume=$HOME/neo4j/conf:/conf \
neo4j:3.1 dump-config

Related

Mont a volume in host directoy

I am running an application with a dockerfile that I made.
I run at first my image with this command:
docker run -it -p 8501:8501 99aa9d3b7cc1
Everything works fine, but I was expecting to see a file in a specific folder of my directory of the app, which is an expected behaviour. But running with docker, seems like the application cannot write in my host directory.
Then I tried to mount a volume with this command
docker 99aa9d3b7cc1:/output .
I got this error docker: invalid reference format.
Which is the right way to persist the data that the application generates?
Use docker bind mounts.
e.g.
-v "$(pwd)"/volume:/output
The files created in /output in the container will be accessible in the volume folder relative to where the docker command has been run.

Find docker image files on Windows

I'm using Keycloak on docker and I have to change some files to build a custom theme in docker's image for Keycloak, but I can't find these files on my Windows system. How can I find and change docker images files on Windows?
Once an image has been built, you can't modify it. In general, you can't directly modify the files in images or containers from outside of Docker.
You can build a custom Docker image starting FROM any image you want, and then COPY files into the theme directory:
FROM jboss/keycloak
COPY my-theme/ /opt/jboss/themes/my-theme/
ENV KEYCLOAK_DEFAULT_THEME=my-theme
docker-build -t my-keycloak .
docker run -p 8080:8080 my-keycloak
Or, you can bind-mount a host directory into the container. This will allow you to directly edit the files in the host directory, and they will be reflected in the container (and vice versa), but it will not produce a reusable image that you could distribute.
docker run \
-p 8080:8080 \
-v $PWD/my-theme:/opt/jboss/keycloak/my-theme \
-e KEYCLOAK_DEFAULT_THEME=my-theme \
jboss/keycloak

Is there a way to automate the creation of Docker Image?

I needed to create a Docker image of a Springboot application and I achieved that by creating a Dockerfile and building it into an image. Then, I used "docker run" to bring up a container. This container is used for all the activities for which my application was written.
My problem, however, is that the JAR file that I have used needs constant changes and that requires me to rebuild the Docker image everytime. Furthermore, I need to take the contents of the earlier running Docker container and transfer it into a container created from the newly built image.
I know this whole process can be written as a Shell script and exected every time I have changes on my JAR file. But, is there any tool I can use to somehow automate it in a simple manner?
Here is my Dockerfile:
FROM java:8
WORKDIR /app
ADD ./SuperApi ./SuperApi
ADD ./config ./config
ADD ./Resources ./Resources
EXPOSE 8000
CMD java -jar SuperApi/SomeName.jar --spring.config.location=SuperApi/application.properties
If you have a JAR file that you need to copy into an otherwise static Docker image, you can use a bind mount to save needing to rebuild repeatedly. This allows for directories to be shared from the host into the container.
Say your project directory (the build location where the JAR file is located) on the host machine is /home/vishwas/projects/my_project, and you need to have the contents placed at /opt/my_project inside the container. When starting the container from the command line, use the -v flag:
docker run -v /home/vishwas/projects/my_project:/opt/my_project [...]
Changes made to files under /home/vishwas/projects/my_project locally will be visible immediately inside the container1, so no need to rebuild (and probably no need to restart) the container.
If using docker-compose, this can be expressed using a volumes stanza under the services listing for that container:
volumes:
- type: bind
source: /home/vishwas/projects/my_project
target: /opt/my_project
This works for development, but later on, it's likely you'll want to bundle the JAR file into the image instead of sharing from the host system (so it can be placed into production). When that time comes, just re-build the image and add a COPY directive to the Dockerfile:
COPY /home/vishwas/projects/my_project /opt/my_project
1: Worth noting that it will default to read/write, so the container will also be able to modify your project files. To mount as read-only, use: docker run -v /home/vishwas/projects/my_project:/opt/my_project:ro
You are looking for docker compose
You can build and start containers with a single command using compose.

Mount image multiple times in docker

As far as I understand Docker, it should be very simple to create different environments like dev or prod by just mounting an image multiple times by just running "docker run" more than once.
However, I've build an image extending neo4j to have a custom configured neo4j image with the following Dockerfile:
FROM neo4j:3.5
COPY neo4j.conf /var/lib/neo4j/conf/neo4j.conf
COPY apoc-3.5.0.1.jar /var/lib/neo4j/plugins/apoc.jar
I've build it with
docker build -t myneo .
Now I'v started it 2 times using a script.bat like so:
docker run -d --rm --name neo4j-prod -p 10074:7474 -p 10087:7687 myneo
docker run -d --rm --name neo4j-dev -p 7474:7474 -p 7687:7687 myneo
Now I have 2 instances reachable under :10074 and :7474, however, when I create some date in one of those, it appears in the other one as well. What am I doing wrong?
Sadly, I have to work on Windows.
Looks like your both Neo4j instances are pointing to the same database on the file system.
You can change the database location in neo4j.conf file.
By default database is stored in data directory.
You can uncomment following line and change it as per your env.
#dbms.directories.data=data
like
dbms.directories.data=prod_data
Another option is to keep the database location the same and use the different databases for prod and dev.
You can uncomment and change the active database name on the following line.
#dbms.active_database=graph.db
like
dbms.active_database=prod_graph.db
EDIT:
If above is not the issue then, maybe you are connecting to the same host from Neo4j browser (check host in bolt connection).
Refer following screenshot:
If your issue was due to copying the same config file which might contaib common data then you might consider changing thecway you modify it for separate environments.
According to Configuration docs. There are multiple way to customize the config file - copying the file which you are using is one of them - but as you intend to use the same image for multiple environment it would be better to also configure neo4j based on environment variables to avoid making the same configuration for both like passwords or databases and so on, for example:
docker run \
--detach \
--publish=7474:7474 --publish=7687:7687 \
--volume=$HOME/neo4j/data:/data \
--volume=$HOME/neo4j/logs:/logs \
--env=NEO4J_dbms_memory_pagecache_size=4G \
neo4j:3.5
And your Dockerfile will be like this:
FROM neo4j:3.5
COPY apoc-3.5.0.1.jar /var/lib/neo4j/plugins/apoc.jar
So you might want to enable database authentication in production but not in development then you will have to do the following:
# For production
docker run -d --rm --name neo4j-prod -e NEO4J_dbms.security.auth_enabled=true -p 10074:7474 -p 10087:7687 myneo
# For development
docker run -d --rm --name neo4j-dev -e NEO4J_dbms.security.auth_enabled=false -p 7474:7474 -p 7687:7687 myneo
Following this way will make easy to deploy, reconfigure and keeping the configuration separate, also when you go with something like docker-compose things will be easier.
More details can be found in here

How to specify docker image path on command line without editing configuration setting?

I have my docker container images in different directories. And I would like to specify the path of the directory in the docker -run command. There is a method to change this path by editing the '-g' option in the configuration file, but it requires to restart the docker deamon. Is there any way to specify the docker image path in the docker-run command itself?
Docker must have the knowledge of not just your image physical location, but its complete tree. because docker image is made up of layers, where each layer is built with one Dockerfile command.
Hence, you should let docker register / know all the images from the directory where the images are present. Moreover, if you have physically copied these images from another machine, they would not work unless they are registered / tagged within Docker engine.
The short answer to your question is NO, it is not possible.
Docker engine itself should manage the images, you could do all what docker engine is doing by changing all the configuration files it maintains internally, because all of them are plain text. But it is definitely not worth your time, and you are better off with docker managing the images itself.

Resources