You need a fixed IP for a container.
IntermediateScenarioNetworking and Compose
Answer
Situation read → Some legacy firewalls or configs require static IPs.
What I'd do →
docker network create --subnet 172.30.0.0/24 fixed
docker run --network fixed --ip 172.30.0.10 myapp
In Compose, set ipam config and ipv4_address.
Why → Static IPs only work on user-defined networks with a subnet.
Interview tip → Prefer DNS names; static IPs signal tight coupling.
More on Networking and Compose
Containers on the default bridge cannot resolve each other by name. Why, and what do you do?BeginnerHow do you expose a container only to the local host, not the internet?BeginnerDesign a Compose file for web + api + postgres + redis with correct startup ordering.IntermediateFrontend must reach the API but not the database. Segment the network.IntermediateA container needs to call a service running on the Docker host.BeginnerWhen would you use `--network host`?Intermediate