- TechOps Examples
- Posts
- Dockerfile vs docker-compose.yaml for Network Configuration
Dockerfile vs docker-compose.yaml for Network Configuration
TechOps Examples
Hey — It's Govardhana MK 👋
Welcome to another technical edition.
Every Tuesday – You’ll receive a free edition with a byte-size use case, remote job opportunities, top news, tools, and articles.
Every Thursday and Saturday – You’ll receive a special edition with a deep dive use case, remote job opportunities and articles.
👋 Before we begin... a big thank you to today's sponsor OPENOPS
If you work in FinOps, we at OpenOps are committed to partnering with your “daily driver” platforms - the tools you work with each and every day.
To stand by that promise, we are launching over 15 new integrations with major FinOps platforms this month, including all the brands you know and love.
✅ You’ll learn how to automate cloud cost optimization with our platform partners
⚙️ We’ll show real workflows across all major FinOps platforms and major CSPs
🙋♀️ And yes—ask anything. We’ll be there, live, answering as we go.
If you’re not a subscriber, here’s what you missed last week.
To receive all the full articles and support TechOps Examples, consider subscribing:
IN TODAY'S EDITION
🧠 Use Case
Dockerfile vs docker-compose.yaml for Network Configuration
🚀 Top News
👀 Remote Jobs
Invisible Technologies is hiring a DevOps Engineer
Remote Location: Worldwide
CrowdStrike is hiring a Staff IT Monitoring Engineer/SRE
Remote Location: India
📚️ Resources
🛠️ TOOL OF THE DAY
kopia - Cross-platform backup tool for Windows, macOS & Linux with fast, incremental backups, client-side end-to-end encryption, compression and data deduplication. CLI and GUI included.
🧠 USE CASE
Dockerfile vs docker-compose.yaml for Network Configuration
An entry level DevOps engineer on my team once explained this to me:
“In my docker-compose.yaml, I assign a static IP to a web app container like this:
networks:
custom01:
ipv4_address: x.x.x.x
It works. The app is reachable at a fixed IP, and Nginx can route traffic to it.
But the app needs to be built from source. I use a Dockerfile to install packages, build binaries, and set up the environment.
I tried assigning a network inside the Dockerfile, but it didn’t work”.
He had hit a common mistake. The Dockerfile and docker-compose.yaml solve different problems.
Dockerfile defines how the image is built. It controls what is inside the container (OS, packages, source code, build steps).

docker-compose.yaml defines how the container is run. It handles ports, volumes, networks, and container relationships.

You cannot attach a container to a network or assign it a specific IP address within a Dockerfile. That configuration is handled at runtime, typically using a docker-compose.yaml file.
The solution
Build the app image using the Dockerfile. Use docker-compose.yaml to run it with proper network settings.
services:
app:
build: ./app
networks:
custom01:
ipv4_address: 192.168.50.10
nginx:
image: nginx:alpine
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
networks:
custom01:
ipv4_address: 192.168.50.5
networks:
custom01:
external: true
Create the network first:
docker network create --driver=bridge --subnet=192.168.50.0/24 custom01
Your Nginx config can then route traffic to http://192.168.50.10.
Takeaway
Use the Dockerfile to define how the image is built.
Use docker-compose.yaml to control how containers run and connect.
Network setup always belongs to the runtime, not the build phase.