docker-compose how to use minio in- and outside of the docker network
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
When MinIO runs in Docker Compose, the address you use depends on where the client runs. Containers inside the same Compose network should talk to MinIO by service name, while tools running on your host machine should use the published host port such as localhost:9000.
Most connection problems come from mixing those two contexts. The credentials may be right and MinIO may be healthy, but the client is still using the wrong hostname for its network location.
A Basic Compose Setup
A minimal Compose file looks like this:
This exposes:
- '
9000for the S3-compatible API' - '
9001for the MinIO console'
If you add an application service to the same Compose file, Docker automatically puts both services on the same default network unless you override that behavior.
Access from Another Container in the Same Compose Network
Inside the Docker network created by Compose, use the service name minio as the hostname.
Do not use localhost here. Inside a container, localhost means that container itself, not the MinIO container.
Access from Outside Docker
From your host machine, use the published host port.
For the web console, open http://localhost:9001 in your browser.
Use Different Configuration per Runtime Context
If the same application sometimes runs in Docker and sometimes directly on the host, externalize the endpoint into environment variables.
for in-network containers, and:
for host-based clients.
That keeps the code the same while only the deployment config changes.
Common Networking Mistakes
The classic errors are:
- using
localhostfrom one container to reach another container - using
minio:9000from the host machine, which usually does not resolve - publishing ports but then accidentally connecting to the container-internal address from outside Docker
A simple mental model helps:
- inside Docker network: use service names
- outside Docker network: use hostnames and published ports
This distinction is the same for most Compose-managed services, not just MinIO, so it is a useful habit beyond object storage. It is one of the first networking rules worth memorizing.
Buckets and Health Checks
Once connectivity works, a quick smoke test is to create a bucket or list buckets.
This confirms that both networking and credentials are correct.
Common Pitfalls
- Using
localhostinside a container when you really need the Compose service name. - Using the service name from the host machine when only the published port is reachable there.
- Forgetting to publish port
9000or9001when host access is required. - Hard-coding one endpoint in code even though the application runs both inside and outside Docker.
- Treating a successful console login as proof that another container can also resolve the same endpoint.
Summary
- MinIO has different correct hostnames depending on where the client runs.
- Inside the Compose network, use
minio:9000. - Outside Docker, use
localhost:9000or the host/IP where the port is published. - Keep the endpoint configurable so the same code works in both contexts.
- Most MinIO Compose connection bugs are network-context mistakes, not MinIO bugs.
Related reading
- docker-compose INTERNAL ERROR cannot create temporary directory
- docker-compose kafka wait for zookeeper and schema-registry wait for kafka
- Docker-compose node_modules not present in a volume after npm install succeeds
- docker-compose not showing any changes to code
- docker buildkit not supported by daemon in AWS EKS kubernetes cluster
- Docker container live migration in kubernetes
- Docker-Compose persistent data MySQL
- Docker-Compose Postgresql import dump
System design interview problems on this topic
- Design a Container Orchestration System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design GitHub Actions: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.