How to Run Minio in Docker and Docker Compose

Object storage is a computer data storage that manages data as objects, as opposed to other storage architectures like file systems which manages data as a file hierarchy, and block storage which manages data as blocks within sectors and tracks.

Object storage is used for housing videos and photos, music, and files for online collaboration. In object storage, data is sectioned off into units (aka “objects”) where it is stored in a flat environment. Each object includes:

  • Data
  • Metadata
  • Unique identifier

All data blocks for a file are contained together as an object and are stored in what is called a storage pool. To access data, the storage system uses a unique identifier and metadata to find the object. Data can be accessed using RESTful APIs, HTTP, and HTTPS.

Object storage is crucial to the functioning of cloud services and applications. And because of the way object storage works, you can scale very quickly, up to petabytes and exabytes (so long as the machine in question has the space).

MinIO is a high performance object storage solution that provides an Amazon Web Services S3-compatible API and supports all core S3 features. MinIO is built to deploy anywhere - public or private cloud, baremetal infrastructure, orchestrated environments, and edge infrastructure. It is a high performance distributed object storage server, designed for large-scale private cloud infrastructure. MinIO is designed in a cloud-native manner to scale sustainably in multi-tenant environments.

In this guide, we will explore how to deploy standalone minio server in docker and docker-compose.

# Prerequisites

Before proceeding ensure that you have docker installed. Please checkout How to Install and Use Docker in Ubuntu 22.04 if you need help installing.

# Start the container

Create a data directory

1
mkdir -p ~/minio/data

Run minio with docker

1
2
3
4
5
6
7
8
docker run \
   -p 9000:9000 \
   -p 9090:9090 \
   --name minio \
   -v ~/minio/data:/data \
   -e "MINIO_ROOT_USER=admin" \
   -e "MINIO_ROOT_PASSWORD=Secure123$" \
   quay.io/minio/minio server /data --console-address ":9090"

The above commands works this way:

  • mkdir creates a new local directory at ~/minio/data in your home directory.
  • docker run starts the MinIO container.
  • -p binds a local port to a container port.
  • -name creates a name for the container.
  • -v sets a file path as a persistent volume location for the container to use. When MinIO writes data to /data, that data mirrors to the local path ~/minio/data, allowing it to persist between container restarts. You can replace ~/minio/data with another local file location to which the user has read, write, and delete access.
  • -e sets the environment variables MINIO_ROOT_USER and MINIO_ROOT_PASSWORD, respectively. These set the root user credentials. Change the example values to use for your container.

# Runing MinIO using Docker Compose

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Ensure you have docker-compose before proceeding. If you are on Linux, use this commane to set up

1
2
curl -L -o /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-linux-x86_64
sudo chmod +x /usr/local/bin/docker-compose

Confirm that it is working as expected by checking the version

1
2
3
$ docker-compose -v

Docker Compose version v2.20.2

Create a docker-compose.yaml file in your working directory.

1
2
3
4
mkdir ~/minio
cd ~/minio

vim docker-compose.yaml

Add this content:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
version: '3.9'

services:
  minio:
    image: quay.io/minio/minio
    command: server /data --console-address ":9090"
    restart: always
    ports:
      - 9000:9000
      - 9090:9090
    volumes:
      - ~/minio/data:/data
    environment:
      - MINIO_ROOT_USER=admin
      - MINIO_ROOT_PASSWORD=Secure123$
    networks:
      - minio_net

networks:
  minio_net:

Start the container

1
2
3
4
5
$ docker-compose up -d

[+] Running 2/2
 ✔ Network minio_minio_net  Created                0.1s
 ✔ Container minio-minio-1  Started

To confirm that it is working as expected, check docker-compose processes

1
2
3
$ docker-compose ps
NAME                IMAGE                 COMMAND                  SERVICE             CREATED             STATUS              PORTS
minio-minio-1       quay.io/minio/minio   "/usr/bin/docker-ent…"   minio               55 seconds ago      Up 53 seconds       0.0.0.0:9000->9000/tcp, :::9000->9000/tcp, 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp

# Connect your Browser to the MinIO Server

Access the MinIO Console by going to a browser and going to http://127.0.0.1:9000 or one of the Console addresses specified in the minio server command’s output. For example, console: http://10.2.11.9:9090 http://127.0.0.1:9090 in the example output indicates two possible addresses to use for connecting to the Console.

While port 9000 is used for connecting to the API, MinIO automatically redirects browser access to the MinIO Console.

Log in to the Console with the credentials you defined in the MINIO_ROOT_USER and MINIO_ROOT_PASSWORD environment variables.

# Install the MinIO Client

The MinIO Client allows you to work with your MinIO volume from the commandline.

# Setting up in linux

Download the mc client and install it to a location on your system PATH such as /usr/local/bin. You can alternatively run the binary from the download location.

1
2
3
wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc
sudo mv mc /usr/local/bin/mc

Use mc alias set to create a new alias associated to your local deployment. You can run mc commands against this alias:

1
2
mc alias set local http://127.0.0.1:9000 {MINIO_ROOT_USER} {MINIO_ROOT_PASSWORD}
mc admin info local

Replace {MINIO_ROOT_USER} and {MINIO_ROOT_PASSWORD} with the credentials you defined for the container with the -e flags.

The mc alias set takes four arguments:

  • The name of the alias
  • The hostname or IP address and port of the MinIO server
  • The Access Key for a MinIO user
  • The Secret Key for a MinIO user

# Conclusion

You can use the MinIO Console for general administration tasks like Identity and Access Management, Metrics and Log Monitoring, or Server Configuration. Each MinIO server includes its own embedded MinIO Console.

Last updated on Mar 20, 2024 17:19 +0300
comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy