A Neo4j container (docker) with initial data in it

后端 未结 2 1704
离开以前
离开以前 2021-01-06 03:46

Other database dockers that I\'ve worked with (like Postgres) have a mechanism to import some initial data into their empty instance once the container starts for the first

相关标签:
2条回答
  • 2021-01-06 04:36

    This could be achieved... There are 2 requirements:

    1. set initial password, which could be achieved using bin/neo4j-admin set-initial-password <password> and then
    2. import data from file in cypher format cat import/data.cypher | NEO4J_USERNAME=neo4j NEO4J_PASSWORD=${NEO4J_PASSWD} bin/cypher-shell --fail-fast

    Sample Dockerfile may look like this

    FROM neo4j:3.2
    
    ENV NEO4J_PASSWD neo4jadmin
    ENV NEO4J_AUTH neo4j/${NEO4J_PASSWD}
    
    COPY data.cypher /var/lib/neo4j/import/
    
    VOLUME /data
    
    CMD bin/neo4j-admin set-initial-password ${NEO4J_PASSWD} || true && \
        bin/neo4j start && sleep 5 && \
        for f in import/*; do \
          [ -f "$f" ] || continue; \
          cat "$f" | NEO4J_USERNAME=neo4j NEO4J_PASSWORD=${NEO4J_PASSWD} bin/cypher-shell --fail-fast && rm "$f"; \
        done && \
        tail -f logs/neo4j.log
    

    Building image sudo docker build -t neo4j-3.1:loaddata .

    And running container docker run -it --rm --name neo4jtest neo4j-3.1:loaddata

    0 讨论(0)
  • 2021-01-06 04:40

    example of docker-compose for Neo4j

    version: '3'
    services:
      # ...
    
      neo4j:
        image: 'neo4j:4.1'
        ports:
          - '7474:7474'
          - '7687:7687'
        volumes:
          - '$HOME/data:/data'
          - '$HOME/logs:/logs'
          - '$HOME/import:/var/lib/neo4j/import'
          - '$HOME/conf:/var/lib/neo4j/conf'
        environment:
          NEO4J_AUTH : 'neo4j/your_password'
        # ...
    
    0 讨论(0)
提交回复
热议问题