docker-compose
minio
docker network
containerization
cloud storage

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.

Practice system design

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:

yaml
1services:
2  minio:
3    image: minio/minio:latest
4    command: server /data --console-address ":9001"
5    environment:
6      MINIO_ROOT_USER: minioadmin
7      MINIO_ROOT_PASSWORD: minioadmin123
8    ports:
9      - "9000:9000"
10      - "9001:9001"
11    volumes:
12      - minio-data:/data
13
14volumes:
15  minio-data:

This exposes:

  • '9000 for the S3-compatible API'
  • '9001 for 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.

python
1from minio import Minio
2
3client = Minio(
4    "minio:9000",
5    access_key="minioadmin",
6    secret_key="minioadmin123",
7    secure=False,
8)

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.

python
1from minio import Minio
2
3client = Minio(
4    "localhost:9000",
5    access_key="minioadmin",
6    secret_key="minioadmin123",
7    secure=False,
8)

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.

env
MINIO_ENDPOINT=minio:9000

for in-network containers, and:

env
MINIO_ENDPOINT=localhost:9000

for host-based clients.

That keeps the code the same while only the deployment config changes.

Common Networking Mistakes

The classic errors are:

  • using localhost from one container to reach another container
  • using minio:9000 from 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.

python
if not client.bucket_exists("demo-bucket"):
    client.make_bucket("demo-bucket")

This confirms that both networking and credentials are correct.

Common Pitfalls

  • Using localhost inside 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 9000 or 9001 when 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:9000 or 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.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design