Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
81 views
in Technique[技术] by (71.8m points)

Binding error when use same port on different IP in Docker

I am using 3 docker containers, service_api and message_api are in php7.2-apache, frontend is node:12.20-alpine, and when I use a different port for every container, everything works great.

But when I want to set that three IP addresses (127.0.0.44, 127.0.0.84 and 0.0.0.0) point on different containers with ports 443 and 80, I am getting errors that ports are already been used.

Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use

Part with ports for my message api in my docker-compose.yml file looks like this:

    hostname: message-api.localhost
    ports:
      - 127.0.0.84:80:80
      - 127.0.0.84:443:443

It's similar config in other containers too.

My wanted result would be that I can access message-api.localhost, service-api.localhost and localhost on ports 443 and 80 and depending from URL to point on the appropriate container.

The output of command docker ps would look something like this then:

CONTAINER ID        IMAGE                   COMMAND                                PORTS                                   NAMES
11a4f381cc60        docker_service_api   "docker-php-entrypoi…"        127.0.0.44:443->443/tcp, 127.0.0.44:80->80/tcp   service_api
31b45fcf60fb        docker_message_api   "docker-php-entrypoi…"        127.0.0.84:443->443/tcp, 127.0.0.84:80->80/tcp   message_api
8a9ccc0c069d        docker_frontend      "docker-php-entrypoi…"        0.0.0.0:80->80/tcp                            frontend
de3113439af5        mysql:5.7            "docker-entrypoint.s…"        3306/tcp, 0.0.0.0:3306->3306/tcp              mysql57

If this is not possible in this way, can you suggest to me Docker architecture where this wanted result would be possible?

question from:https://stackoverflow.com/questions/65830711/binding-error-when-use-same-port-on-different-ip-in-docker

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...