首页 > 解决方案 > 在docker中多次挂载图像

问题描述

据我了解Docker,通过多次运行“docker run”多次安装图像来创建不同的环境(如dev或prod)应该非常简单。

但是,我已经构建了一个扩展 neo4j 的图像,以使用具有以下 Dockerfile 的自定义配置 neo4j 图像:

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

我已经用

docker build -t myneo .

现在我已经使用 script.bat 启动了 2 次,如下所示:

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

现在我在 :10074 和 :7474 下可以访问 2 个实例,但是,当我在其中一个中创建某个日期时,它也会出现在另一个中。我究竟做错了什么?可悲的是,我必须在 Windows 上工作。

标签: windowsdockerneo4jdockerfile

解决方案


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


推荐阅读