Skip to content

Commit 3e3f6f1

Browse files
author
Grok Compression
committed
s3 emulation: update minio docker to alpine with compiled binaries
1 parent ac33404 commit 3e3f6f1

File tree

4 files changed

+50
-32
lines changed

4 files changed

+50
-32
lines changed

network/Dockerfile

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
# MinIO Dockerfile
22

3-
# Use Ubuntu as the base image
4-
FROM ubuntu:latest
3+
# Builder stage to compile MinIO and mc from source
4+
FROM alpine:latest AS builder
5+
6+
# Install Go for building
7+
RUN apk add --no-cache go
8+
9+
# Set GOPATH and compile minio and mc
10+
ENV GOPATH=/go
11+
RUN go install github.com/minio/minio@latest && \
12+
go install github.com/minio/mc@latest
13+
14+
# Final stage
15+
FROM alpine:latest
516

617
# Install dependencies
7-
RUN apt-get update && apt-get install -y \
8-
wget \
18+
RUN apk add --no-cache \
919
ca-certificates \
1020
curl \
1121
iproute2 \
1222
openssl \
13-
&& rm -rf /var/lib/apt/lists/*
14-
15-
# Download MinIO server binary
16-
RUN wget https://dl.min.io/server/minio/release/linux-amd64/minio \
17-
&& chmod +x minio \
18-
&& mv minio /usr/local/bin/
23+
&& rm -rf /var/cache/apk/*
1924

20-
# Download MinIO client (mc) binary
21-
RUN wget https://dl.min.io/client/mc/release/linux-amd64/mc \
22-
&& chmod +x mc \
23-
&& mv mc /usr/local/bin/
25+
# Copy compiled binaries from builder
26+
COPY --from=builder /go/bin/minio /usr/local/bin/minio
27+
COPY --from=builder /go/bin/mc /usr/local/bin/mc
2428

2529
# Create directories for data and certificates
2630
RUN mkdir -p /data /root/.minio/certs
@@ -41,10 +45,8 @@ EXPOSE 9000 9001
4145
# Set the working directory
4246
WORKDIR /root
4347

44-
# Set environment variables for credentials and domain
45-
ENV MINIO_ROOT_USER=minioadmin \
46-
MINIO_ROOT_PASSWORD=minioadmin \
47-
MINIO_DOMAIN=minio.example.com
48+
# Set environment variable for domain (non-sensitive default)
49+
ENV MINIO_DOMAIN=minio.example.com
4850

4951
# Use custom entrypoint to configure virtual host support
5052
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

network/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ MinIO is an open-source, high-performance, distributed object storage system des
2323
## Build/run docker
2424

2525
docker volume create minio-data
26-
docker build -t minio-ubuntu .
26+
docker build -t minio-alpine .
2727

2828
### Run the Docker container
2929

3030
```
31-
docker run -d --rm --cap-add=NET_ADMIN -v minio-data:/data --name minio-container-latest -p 9000:9000 -p 9001:9001 minio-ubuntu
31+
docker run -d --rm --cap-add=NET_ADMIN -v minio-data:/data --name minio-container -p 9000:9000 -p 9001:9001 minio-alpine
3232
3333
```
3434

@@ -56,6 +56,10 @@ docker exec -it minio-container /bin/sh
5656

5757
Go to `localhost:9001` on host and create `grok` bucket
5858

59+
or
60+
61+
`mc mb local/grok --insecure`
62+
5963

6064
### Minio Client
6165

@@ -86,6 +90,11 @@ export AWS_S3_ENDPOINT="http://localhost:9000"
8690
export AWS_VIRTUAL_HOSTING=False
8791
```
8892

93+
Also map `minio.example.com` to localhost
94+
95+
`sudo bash -c 'echo "127.0.0.1 minio.example.com" >> /etc/hosts'`
96+
97+
8998
### See logs
9099

91100
`docker logs minio-container`

network/emulate.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sudo modprobe sch_netem 2>/dev/null || echo "sch_netem already loaded"
88

99
# Container configuration
1010
CONTAINER_NAME="minio-container"
11-
IMAGE_NAME="minio-ubuntu"
11+
IMAGE_NAME="minio-alpine"
1212
MINIO_DOMAIN="minio.example.com"
1313
MINIO_BUCKETS="grok" # Explicitly configure the 'grok' bucket
1414
MINIO_ROOT_USER="minioadmin"
@@ -18,8 +18,8 @@ MINIO_ROOT_PASSWORD="minioadmin"
1818
docker stop "$CONTAINER_NAME" 2>/dev/null || true
1919
docker rm "$CONTAINER_NAME" 2>/dev/null || true
2020

21-
# Run MinIO container with virtual host support
22-
docker run -d --rm \
21+
# Run MinIO container with virtual host support (removed --rm for debugging)
22+
docker run -d \
2323
--cap-add=NET_ADMIN \
2424
-v minio-data:/data \
2525
-v minio-certs:/root/.minio/certs \
@@ -32,21 +32,26 @@ docker run -d --rm \
3232
-e "MINIO_BUCKETS=$MINIO_BUCKETS" \
3333
"$IMAGE_NAME"
3434

35-
# Wait briefly for container to start
36-
sleep 2
35+
# Wait for container to start and be inspectable (loop up to 10s)
36+
for i in $(seq 1 10); do
37+
if docker inspect "$CONTAINER_NAME" &> /dev/null; then
38+
break
39+
fi
40+
sleep 1
41+
done
3742

3843
# Get container PID
3944
PID=$(docker inspect "$CONTAINER_NAME" | grep '"Pid":' | head -n 1 | awk '{print $2}' | tr -d ',')
4045

4146
if [ -z "$PID" ] || [ "$PID" -eq 0 ]; then
42-
echo "Error: Couldn't get PID for $CONTAINER_NAME"
47+
echo "Error: Couldn't get PID for $CONTAINER_NAME (check 'docker logs $CONTAINER_NAME' for startup issues)"
4348
exit 1
4449
fi
4550

4651
echo "Container PID: $PID"
4752

48-
# Enter network namespace and apply netem delay with the variable
49-
sudo nsenter -t "$PID" -n /bin/bash -c "\
53+
# Enter network namespace and apply netem delay with the variable (use /bin/sh for Alpine compat)
54+
sudo nsenter -t "$PID" -n /bin/sh -c "\
5055
tc qdisc replace dev eth0 root netem delay ${DELAY_MS}ms && \
5156
tc qdisc show dev eth0\
5257
"

network/entrypoint.sh

100644100755
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
# Ensure /data and /root/.minio/certs are preserved
44
if [ ! -d /data ]; then
@@ -11,7 +11,7 @@ if [ ! -d /root/.minio/certs ]; then
1111
fi
1212

1313
# Get the container's IP address
14-
CONTAINER_IP=$(ip addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -1)
14+
CONTAINER_IP=$(ip addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f1 | head -1)
1515
if [ -z "$CONTAINER_IP" ]; then
1616
echo "Failed to determine container IP address"
1717
exit 1
@@ -25,11 +25,13 @@ else
2525
echo "$CONTAINER_IP $MINIO_DOMAIN" >> /etc/hosts
2626

2727
if [ ! -z "$MINIO_BUCKETS" ]; then
28-
IFS=',' read -ra BUCKET_ARRAY <<< "$MINIO_BUCKETS"
29-
for bucket in "${BUCKET_ARRAY[@]}"; do
28+
old_IFS="$IFS"
29+
IFS=','
30+
for bucket in $MINIO_BUCKETS; do
3031
echo "$CONTAINER_IP ${bucket}.$MINIO_DOMAIN" >> /etc/hosts
3132
echo "Added ${bucket}.$MINIO_DOMAIN to /etc/hosts"
3233
done
34+
IFS="$old_IFS"
3335
fi
3436
fi
3537

0 commit comments

Comments
 (0)