简体   繁体   English

不同容器的相同docker映像

[英]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.

相关问题 多个 Docker 容器,相同的镜像,不同的配置 - Multiple Docker containers, same image, different config 如何从同一个 Docker 图像将各种输入写入不同容器中的同一个文件? - How to write various inputs into the same file in different containers from the same Docker image? 如何通过在不同主机端口上运行相同的 docker-compose 文件来创建相同映像的多个容器? - How to create multiple containers of same image by running same docker-compose file on different host ports? 在同一 docker 主机上的不同容器上托管站点 - Hosting site on different containers on same docker host 具有相同图像和内存使用率的多个Docker容器 - Multiple docker containers of same image and memory usage 使用相同图像的许多容器进行Docker崩溃测试 - Docker crash test with many containers of the same image 如何在docker-compose中编写变量,运行多个使用相同映像但端口不同的容器 - How to write variable in docker-compose, running multiple containers which uses the same image but their ports are different 在同一主机/不同端口上运行不同的Docker容器 - Running different docker containers on same host/different port 3个不同的应用程序和Docker容器 - 3 different applications and docker containers 如何为同一主机中的每个Docker容器设置不同的静态IP? - How to set different static IPs to each docker containers with in the same host?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM