Skip to content

How to create a custom MinIO image for testing purposes

Cesar Celis Hernandez edited this page Mar 9, 2022 · 6 revisions

Introduction

All started because of this task: https://github.com/miniohq/engineering/issues/441 that I got assigned in order to improve our coverage of this repository. The task is simple if you have KMS enabled in MinIO but that is not the case when I got this task. If you are interested in KMS, I recommend you to read more on the documentation available at: https://docs.min.io/docs/minio-kms-quickstart-guide.html

Anyway, the center of this discussion is more on the fact that I wanted to learn how to modify a MinIO Docker Image with the intention of putting KMS on top of it, in this known how document, I will focus in just a simple task, we are going to show how to customize your MinIO image and that will let you go further with any other related task like mine. Ok, without further ado, let's start.

Get MinIO Binary for the architecture you are planning to use

Architecture

There are several ways in which you can get MinIO binary. You can either call make all at minio/minio repo and get the binary compiled with your machine architecture or you can just download directly from: https://min.io/download#/linux

For this particular example, and since I have an Apple M1 Chip, I will proceed to download from the webpage. The reason is simple, I want to compile for Ubuntu Virtual Machines on our GitHub actions. If by mistake you provide your compiled binary to a different architecture, you are going to get this message below:

/usr/bin/docker-entrypoint.sh: line 24: /opt/bin/minio: cannot execute binary file: Exec format error
/usr/bin/docker-entrypoint.sh: line 24: /opt/bin/minio: Success

That means that you are trying to execute a binary from another architecture and this is not possible. So be careful and select the architecture that matches your Docker Container.

Steps

  1. Download minio binary
wget https://dl.min.io/server/minio/release/linux-amd64/minio
chmod +x minio
  1. Clone the repository and modify the files as desired
git clone git@github.com:minio/minio.git

Notice Dockerfile got modified to run ls rather than minio when starting the container:

FROM minio/minio:latest

ENV PATH=/opt/bin:$PATH

COPY ./minio /opt/bin/minio
COPY dockerscripts/docker-entrypoint.sh /usr/bin/docker-entrypoint.sh

ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"]

VOLUME ["/data"]

CMD ["ls"]

Also commented out the pre-append of minio in our docker-entrypoint.sh script:

#!/bin/sh
#

# If command starts with an option, prepend minio.
# if [ "${1}" != "minio" ]; then
#     if [ -n "${1}" ]; then
#         set -- minio "$@"
#     fi
# fi

# su-exec to requested user, if service cannot run exec will fail.
docker_switch_user() {
    if [ -n "${MINIO_USERNAME}" ] && [ -n "${MINIO_GROUPNAME}" ]; then
        if [ -n "${MINIO_UID}" ] && [ -n "${MINIO_GID}" ]; then
            groupadd -g "$MINIO_GID" "$MINIO_GROUPNAME" && \
                useradd -u "$MINIO_UID" -g "$MINIO_GROUPNAME" "$MINIO_USERNAME"
        else
            groupadd "$MINIO_GROUPNAME" && \
                useradd -g "$MINIO_GROUPNAME" "$MINIO_USERNAME"
        fi
        exec setpriv --reuid="${MINIO_USERNAME}" \
             --regid="${MINIO_GROUPNAME}" --keep-groups "$@"
    else
		uname -m
		echo "$@" # minio ls
        exec "$@"
    fi
}

## Switch to user if applicable.
docker_switch_user "$@"
  1. Build the image and run it:
docker buildx build --output=type=docker --platform linux/amd64 -t cesar-tag . -f Dockerfile

As a result, you will get the ls command executed rather than minio

$ docker run 58927d4435d1
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
x86_64
ls
bin
boot
data
dev
etc
home
lib
lib64
licenses
lost+found
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var

Conclusion

If you need a custom MinIO Image for any purpose; then now you know how to achieve that. I will be using these steps to add KMS and create a separate Best Known Method that will have a reference to this one to show the KMS part.