如何使用docker-compose在同一台机器上运行neo4j的两个实例

时间:2019-09-11 08:41:07

标签: neo4j docker-compose

我可以使用docker-compose在同一台机器上运行neo4j的两个实例吗?如果我按照以下设置有一个实例,那么第二个实例的端口设置应该是什么?或我必须做的其他必要设置?

version: '3.2'
services:
    neo4j:
        container_name: Neo4j_test
        image: neo4j:latest
        volumes:
            - ./neo4jdb/data/:/data/ 
            - ./neo4jdb/conf/:/conf/
            - ./neo4jdb/logs/:/logs/             
            - ./neo4jdb/plugins/:/plugins/   
            - ./neo4jdb/import/:/import/ 
        ports:
            - "7474:7474" 
            - "7687:7687"
        environment:
            - NEO4J_apoc_export_file_enabled=true 
            - NEO4J_apoc_import_file_enabled=true 
            - NEO4J_apoc_import_file_use_neo4j_config=true
            - NEO4J_dbms_security_procedures_unrestricted=apoc.*
            - NEO4J_dbms_memory_heap_initial__size=512m
            - NEO4J_dbms_memory_heap_max__size=8G
            - NEO4J_AUTH=neo4j/test
        networks: ['Neo4j']
        restart: unless-stopped

networks: {Neo4j: {}}
# use docker volume to persist data outside of a container.
volumes:
  Neo4j_data:

这里是docker-compose.yml的第二个容器。

version: '3.2'
services:
    neo4j:
        container_name: Neo4j_test2
        image: neo4j:latest
        volumes:
            - ./neodb/data/:/data/ 
            - ./neodb/conf/:/conf/
            - ./neodb/logs/:/logs/             
            - ./neodb/plugins/:/plugins/   
            - ./neodb/import/:/import/ 
        ports:
            - "27474:7474" 
            - "27687:7687"
        environment:
            - NEO4J_apoc_export_file_enabled=true 
            - NEO4J_apoc_import_file_enabled=true 
            - NEO4J_apoc_import_file_use_neo4j_config=true
            - NEO4J_dbms_security_procedures_unrestricted=apoc.*
            - NEO4J_dbms_memory_heap_initial__size=512m
            - NEO4J_dbms_memory_heap_max__size=2G
            - NEO4J_AUTH=neo4j/test
        networks: ['Neo4j_lab']
        restart: unless-stopped

networks: {Neo4j_lab: {}}
# use docker volume to persist data outside of a container.
volumes:
  Neo4j_lab_data:

我如何分开保存两个容器的数据库?我将这两个docker-compose.yml文件保存在两个单独的目录中。

谢谢

1 个答案:

答案 0 :(得分:1)

您应该将第二个Neo4j容器的端口映射到主机的另一个端口:

ports:
  - "27474:7474" 
  - "27687:7687"

检查https://docs.docker.com/compose/compose-file/#ports的更多信息。