config neo4j in docker-compose.yml?
Hi,
I am new to Docker. I have a Rails app that uses Neo4j graph database, and I would like to run this app in docker. I'd want to use a docker-compose.yml to have two services, one is neo4j and the other is web that links to neo4j. In neo4j service part, I would like to use the neo4j image you created (and hosted in Docker Hub):
neo4j: image: tpires/neo4j ports: - "7474:7474" ....
web: build . ... links: - neo4j
I'd want to run the neo4j image with authentication enabled and a username/password set, just like what you mentioned:
docker run -i -t -d -e NEO4J_AUTH=username:password --name neo4j --cap-add=SYS_RESOURCE -p 7474:7474 tpires/neo4j
How would I do it from within my docker-compose.yml? If neo4j's authentication can't be set in docker-compose.yml, where can I do it?
Thanks for your any input.
Alex
Hi @alexw668
You can see here the reference for environmental variable on docker-compose.yml .
For you case you could either add:
neo4j:
image: tpires/neo4j
environment:
- NEO4J_AUTH: username:password
cap_add:
- SYS_RESOURCE
ports:
- "7474:7474"
Or create a env file, .env and:
neo4j:
image: tpires/neo4j
env_file: .env
cap_add:
- SYS_RESOURCE
ports:
- "7474:7474"
And your .env file would be:
NEO4J_AUTH=username:password
TP
Thanks for your help! I got it running in a docker container! Since I expose the 7474 port to my host (a MacBook Pro), I thought I should be able to browse my database from the browser; I used boot2docker ip to get the host's IP (192.168.59.103), and went http://192.168.59.103:7474, but I got webpage not available response. I remember read it somewhere that with OS X one has to do something for for it to work, but I forget where. Do you have any idea on this?
Again, I appreciate your any help.
Alex
Another question for you, if you don't mind. When I ran both services (neo4j and web) in docker, I saw that my Rails app cannot connect to the neo4j database with the username/password I set in NEO4J_AUTH. Looking at your shell script (build_auth_string.sh) that creates the auth file (under data/dbms), it starts with the user name I set. Looking at the auth file in our other neo4j instance, it always starts with neo4j even though the user name we set is not neo4j. Is it possible that the auth file created by the script is not in the format neo4j demands?
Thanks. Alex
Quick note: In https://github.com/neo4jrb/neo4j/issues/949, it's mentioned that the environment variable of choice is NEO4J_URL (which is the entire URL, including username/pass)
define Neo4j password with docker-compose
neo4j:
image: 'neo4j:4.1'
environment:
NEO4J_AUTH: 'neo4j/your_password'
ports:
- "7474:7474"
volumes:
...