I’m trying to access the Minio S3-API endpoint from within my container, but my app can’t resolve the container name.
The issue is the framework that I’m using, uses the @smithy/middleware-endpoint API, which requires a fully qualified URL. As my MinIO instance is started with the rest of the stack with the endpoint passed into my app on start-up, using the container hostname; http://minio:9000 doesn’t work.
However, I can’t hardcode the IP in my docker-compose file as it changes every time I spin up docker-compose.
My docker-compose file looks something like this:
version: '3.9'
services:
backend:
build: ./backend/tus/.
container_name: backend
ports:
- "8181:8181"
environment:
- MINIO_ENDPOINT=http://minio:9000
depends_on:
- minio
# the minio instance that the back end streams the data uploads to
minio:
image: quay.io/minio/minio
container_name: minio
command: server /data --console-address ":9001"
environment:
- MINIO_ROOT_USER=minioadmin
- MINIO_ROOT_PASSWORD=minioadmin
volumes:
- minio_data:/data
ports:
- "9000:9000"
- "9001:9001"
The code that’s using the environment variable MINIO_ENDPOINT
looks something like this:
/* Set up the s3 store to pass to the tus server */
const datafileS3Store = new S3Store({
s3ClientConfig: {
bucket: process.env.DATAFILE_BUCKET,
region: "eu-west-2",
endpoint: process.env.MINIO_ENDPOINT,
credentials: {
accessKeyId: process.env.MINIO_USERNAME,
secretAccessKey: process.env.MINIO_PASSWORD,
},
},
})
However MinIO outputs its IP addresses on start-up, usually something like:
So, does anyone know how I might be able to get (or even set?) the S3-API IP of the MinIO Instance and pass it into my backend container?
2
Answers
The solution was to create a new network and hardcode the container IP address so that the IP can be passed in as as an env var into the backend.
compose file:
The key thing here is that all other containers need to be added to network:
Your solution would be to create custom network and assigned static IP addresses to the containers. That does allow for a predictable IP address for the MinIO container that can be hard-coded as an environment variable in the backend container.
Each container is assigned a static IP address within the
customnetwork
. The Backend container can directly communicate with the MinIO container using the hard-coded IP address172.20.0.10
.But I would suggest using a BIND9 DNS container (
sameersbn/docker-bind
), in order to declare and resolve a FQDN for minio.See "Running a DNS Server with Docker" from Mike Polinowski for illustration.
minio.example.com
via the BIND9 DNS service, which resolves it to MinIO’s IP address within the Docker network.The docker-compose.yml (v3) would be: