简体   繁体   English

如何使用 docker 容器在两个不同的端口上启动相同的 docker 容器?

[英]How do I start the same docker container on two different ports using docker container?

Since Products and users use all the same files, just run on different ports, how can I just run the same container twice on two different ports?由于产品和用户使用所有相同的文件,只是在不同的端口上运行,我怎么能在两个不同的端口上运行同一个容器两次?

   version: "3.8"
    services:
     users:
        build: 
            context: './backend'
        ports: 
            - "8081:8081"
        command: node services/auth.js
    
     products:
        build:
            context: './backend'
        ports: 
            - "8080:8080"
        command: node services/products.js

     reactapp: 
        stdin_open: true   
        tty: true
        build: 
            context: './frontend/expense-calculator'
        ports: 
            - "3000:3000"
        command: npm start

      

you can follow this article.你可以关注这篇文章。 https://medium.com/@karthi.net/how-to-scale-services-using-docker-compose-31d7b83a6648 https://medium.com/@karthi.net/how-to-scale-services-using-docker-compose-31d7b83a6648

The idea is simple, use one container and map docker container with the host machine's multiple port numbers.这个想法很简单,使用一个容器和 map docker 容器和主机的多个端口号。 for this, you need to scale the container and tell in docker-compose.yml that my container's port is mapped with host machine's these ports like this.为此,您需要缩放容器并在 docker-compose.yml 中告诉我容器的端口与主机的这些端口是这样映射的。

 users:
    build: 
        context: './backend'
    ports: 
        - "8081-8082:8081"
    command: node services/auth.js

and docker-compose up command will be: docker-compose up 命令将是:

docker-compose -f "docker-composetest.yml" up --scale users=2 -d --build

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM