0

I want my Docker containers to work on the same IP. Is it possible? I want them to have the same IP address so that they can link to each other through it.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
S317
  • 29
  • 1
  • 5
  • Containers will be accessible from outside Docker space on the host's IP address and the first port number from the `docker run -p` or Compose `ports:` option. Inside Docker space, the container-private IP addresses are an implementation detail you should ignore; documentation like [Networking in Compose](https://docs.docker.com/compose/networking/) describes how to communicate between containers. "Link" isn't a verb that's useful in modern Docker. – David Maze Dec 29 '20 at 17:53
  • Please describe the actual issue you are encountering. It's possible you don't need to give the containers the same IP address. While that's possible to give containers the same IP (as what though?), the use cases are often misunderstood and it's common for a developer to be mistakenly treating multiple containers as they would multiple processes in a VM. – BMitch Dec 29 '20 at 20:29

1 Answers1

0

Have a look at https://docs.docker.com/compose/networking/ to learn how containers are made accessible with docker-compose.

The gist of it is that you access containers by the name you've given them in the compose-file. So in that example

version: "3.9"
services:
  web:
    build: .
    ports:
      - "8000:8000"
  db:
    image: postgres
    ports:
      - "8001:5432"

you can address the hosts as web and db.

sba
  • 1,829
  • 19
  • 27