
Docker is an open-source project to easily create lightweight, portable, self-sufficient containers from any application. The same container that a developer builds and tests on a laptop can run at scale, in production, on VMs, bare metal, OpenStack clusters, public clouds and more.
Docker Compose can I assign any ipv4 address?
Hello, so I have following Docker Compose yml file and would like to know if I can assign any IPv4 address to the Containers or does it strictly have to be within the 172.x.x.x range? Essentially the goal is to have the Containers communicate with each other and the Host.
version: "3.7" services: db: image: postgres networks: testnet: ipv4_address: 192.168.50.20 ports: - "8001:5432" web: image: nginx:latest networks: testnet: ipv4_address: 192.168.50.10 ports: - "8000:8000" networks: testnet: ipam: driver: default config: - subnet: 192.168.50.0/24
Sort by:
Best
Open comment sort options
Best
Top
New
Controversial
Old
Q&A
Also, instead of hardcoded IP addresses to use for communication, you should look into network aliases for Docker containers. Docker has an internal DNS service which allows for you to reference a Docker container's IP address by either it's container name or network alias. This allows for you to not care about what IP address it is given.
So the idea would be that I don't have to know on the spot which IP addresses are taken. I'll read the documentation on that, thank you.
You should be able to use any subnet on the bridge as long as the subnet isn't used on another interface on the host.
Thanks for the quick answer. I'll double check if that is the case.
Not sure if you have fixed the problem but this docker compose file will communicate between the wordpress and the maria db containers with no additional setup