[英]Same docker image for different containers
I have one problem and maybe misunderstanding with docker images. 我有一个问题,也许对Docker映像有误解。
I need to run two separate mongodb 3.6 containers for my two different projects. 我需要为两个不同的项目运行两个单独的mongodb 3.6容器。 But it seems that if use same image (mongo:3.6), then containers will use the same data, configurations, etc...
但是似乎如果使用相同的映像(mongo:3.6),则容器将使用相同的数据,配置等。
I use docker-compose to run and manage my containers. 我使用docker-compose运行和管理我的容器。 My docker-compose.yml looks like this:
我的docker-compose.yml看起来像这样:
services:
first-mongo:
image: mongo:3.6
container_name: first-mongo
mem_limit: 4g
restart: always
ports:
- '27017:27017'
volumes:
- ${FIRST_MONGO_DB_LOCAL_PATH}:/data/db
- ${FIRST_MONGO_DB_LOCAL_DUMP_PATH}:/data/dumps
- ${FIRST_MONGO_DB_LOCAL_SCRIPTS_PATH}:/data/scripts
second-mongo:
image: mongo:3.6
container_name: second-mongo
mem_limit: 4g
restart: always
ports:
- '27018:27018'
volumes:
- ${SECOND_MONGO_DB_LOCAL_PATH}:/data/db
- ${SECOND_MONGO_DB_LOCAL_DUMP_PATH}:/data/dumps
- ${SECOND_MONGO_DB_LOCAL_SCRIPTS_PATH}:/data/scripts
So, having this configuration my two containers run okay. 因此,使用此配置,我的两个容器可以正常运行。 However, when I took second container's ip address and tried to connect to database I saw the same data as in first container.
但是,当我使用第二个容器的IP地址并尝试连接到数据库时,我看到的数据与第一个容器中的相同。 Also, when I change something, the changes appear in both containers/images.
另外,当我更改某些内容时,更改会同时出现在两个容器/图像中。 Locally, I have different data in the first and second containers.
在本地,我在第一个和第二个容器中有不同的数据。
PS When I change image tag for second container to, for example, mongo:3.5 I see database as I want to (separate data, etc). PS当我将第二个容器的图像标签更改为mongo:3.5时,可以看到想要的数据库(分离数据等)。
I would greatly appreciate any help. 我将不胜感激任何帮助。 Thank you!
谢谢!
I found the solution to that problem. 我找到了解决该问题的方法。 I just changed second-mongo container's ports configuration to:
我刚刚将第二个mongo容器的端口配置更改为:
ports:
- '27018:27017'
Before it was 27018: 27018 . 在27018之前: 27018 。 To be honest, I don't know how it was related, but it works for me now.
老实说,我不知道它是如何关联的,但是它现在对我有用。
Thank you for people who tried to help me! 谢谢那些试图帮助我的人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.