Why i cant get access to minio console from docker container?

huangapple go评论77阅读模式
英文:

Why i cant get access to minio console from docker container?

问题

我想创建一个包含Minio的Docker容器,并同时创建一个存储桶。当我尝试访问控制台(localhost:9001)时,出现错误。我的docker-compose文件有什么问题?

docker-compose.yaml

version: '3'
services:
  minio:
    image: minio/minio:latest
    container_name: minio
    ports:
      - 9000:9000
      - 9001:9001
    volumes:
      - "./data:/data"
      - "./config:/root/.minio"
    environment:
      MINIO_ACCESS_KEY: minio-access-key
      MINIO_SECRET_KEY: minio-secret-key
    command: server /data && server /minio-image/storage --console-address :9001
    networks:
      - minio-network
    restart: always
  create-bucket:
    image: minio/mc:latest
    container_name: create-post-bucket
    environment:
      MINIO_HOST: minio
      MINIO_ACCESS_KEY: minio-access-key
      MINIO_SECRET_KEY: minio-secret-key
    entrypoint: ["sh", "-c"]
    command: "mc mb local/post-bucket || true"
    depends_on:
      - minio
    networks:
      - minio-network
networks:
  minio-network:

请注意,我只提供了docker-compose.yaml文件的翻译,没有提供其他回答。

英文:

I want to create one docker container with minio and also create one bucket at once.When I try to go to the console (localhost:9001) I get an error. Whats wrong with my docker-compose ?

docker-compose.yaml :

version: '3'
services:
  minio:
    image: minio/minio:latest
    container_name: minio
    ports:
      - 9000:9000
      - 9001:9001
    volumes:
      - "./data:/data"
      - "./config:/root/.minio"
    environment:
      MINIO_ACCESS_KEY: minio-access-key
      MINIO_SECRET_KEY: minio-secret-key
    command: server /data && server /minio-image/storage --console-address :9001
    networks:
      - minio-network
    restart: always
  create-bucket:
    image: minio/mc:latest
    container_name: create-post-bucket
    environment:
      MINIO_HOST: minio
      MINIO_ACCESS_KEY: minio-access-key
      MINIO_SECRET_KEY: minio-secret-key
    entrypoint: ["sh", "-c"]
    command: "mc mb local/post-bucket || true"
    depends_on:
      - minio
    networks:
      - minio-network
networks:
  minio-network:

答案1

得分: 2

以下是翻译好的内容:

弃用配置

在启动 minio 容器时,第一个输出是:

minio            | 警告:MINIO_ACCESS_KEY 和 MINIO_SECRET_KEY 已弃用。
minio            | 请使用 MINIO_ROOT_USER 和 MINIO_ROOT_PASSWORD

所以我们应该修复这个问题。

minio 容器的无效命令

接下来,您的 command 似乎存在问题。您运行的是:

server /data && server /minio-image/storage --console-address :9001

但整个命令行都作为参数传递给了 minio 命令,这毫无意义。您可能想要的是:

command: server /data/ --console-address :9001

create-bucket 容器的无效配置

create-bucket 容器尝试运行 mc mb local/post-bucket,但local 别名无效:

[root@e874a3d8e8c8 /]# mc alias list local
local
  URL       : http://localhost:9000
  AccessKey :
  SecretKey :
  API       :
  Path      : auto

minio 服务未在 localhost 上运行。MINIO_HOST 环境变量不被 minio 客户端使用。根据这份文档,您可以在 MC_HOST_<hostname> 环境变量中提供配置。

此外,您的 create-bucket 容器配置的方式可能会导致它在 minio 准备好服务请求之前启动并运行,导致它失败。

使用 Docker 卷而不是绑定挂载

使用绑定挂载 (./data:/data) 而不是命名卷通常不是最佳选择,因为它会导致主机和容器之间的 uid/gid 冲突。除非您确实需要在主机和容器之间共享该目录的内容,否则最好使用命名卷。


我们可以使用以下 docker-compose.yaml 修复所有这些问题:

services:
  minio:
    image: minio/minio:latest
    ports:
      - 9000:9000
      - 9001:9001
    volumes:
      - minio-data:/data
    environment:
      MINIO_ROOT_USER: $MINIO_ROOT_USER
      MINIO_ROOT_PASSWORD: $MINIO_ROOT_PASSWORD
    command: server /data --console-address :9001
    restart: unless-stopped

  create-bucket:
    image: minio/mc:latest
    environment:
      MC_HOST_minio: http://${MINIO_ROOT_USER}:${MINIO_ROOT_PASSWORD}@minio:9000
    entrypoint:
      - sh
      - -c
      - |
        until mc ls minio > /dev/null 2>&1; do
          sleep 0.5
        done

        mc mb minio/post-bucket        

volumes:
  minio-data:

这假设您在您的 .env 文件中设置了 MINIO_ROOT_USERMINIO_ROOT_PASSWORD,像这样:

MINIO_ROOT_USER=admin
MINIO_ROOT_PASSWORD=minio-secret-key

create-bucket 容器中的 entrypoint 脚本会循环,直到 minio 准备好服务请求,然后它会创建存储桶。

使用这个配置运行 docker-compose up 会产生以下结果:

Creating network "container_default" with the default driver
Creating volume "container_minio-data" with default driver
Creating container_minio_1  ... done
Creating create-post-bucket ... done
Attaching to container_minio_1, create-post-bucket
minio_1          | Formatting 1st pool, 1 set(s), 1 drives per set.
minio_1          | WARNING: Host local has more than 0 drives of set. A host failure will result in data becoming unavailable.
minio_1          | MinIO Object Storage Server
minio_1          | Copyright: 2015-2023 MinIO, Inc.
minio_1          | License: GNU AGPLv3 <https://www.gnu.org/licenses/agpl-3.0.html>
minio_1          | Version: RELEASE.2023-06-02T23-17-26Z (go1.19.9 linux/amd64)
minio_1          |
minio_1          | Status:         1 Online, 0 Offline.
minio_1          | S3-API: http://192.168.192.2:9000  http://127.0.0.1:9000
minio_1          | Console: http://192.168.192.2:9001 http://127.0.0.1:9001
minio_1          |
minio_1          | Documentation: https://min.io/docs/minio/linux/index.html
minio_1          | Warning: The standard parity is set to 0. This can lead to data loss.
create-post-bucket | Bucket created successfully `minio/post-bucket`.
create-post-bucket exited with code 0

此时,我可以按预期访问位于我的 Docker 主机上的 http://localhost:9001 的 minio 控制台。

英文:

There are several issues in your docker-compose.yaml.

Deprecated configuration

When starting up the minio container, the very first output is:

minio            | WARNING: MINIO_ACCESS_KEY and MINIO_SECRET_KEY are deprecated.
minio            |          Please use MINIO_ROOT_USER and MINIO_ROOT_PASSWORD

So we should fix that.

Invalid command for minio container

Next, your command seems problematic. You're running:

server /data && server /minio-image/storage --console-address :9001

But that entire command line gets passed as arguments to the minio command, which doesn't make any sense. You probably want:

command: server /data/ --console-address :9001

Invalid configuration for create-bucket container

The create-bucket container attempts to run mc mb local/post-bucket, but the local alias is invalid:

[root@e874a3d8e8c8 /]# mc alias list local
local
  URL       : http://localhost:9000
  AccessKey :
  SecretKey :
  API       :
  Path      : auto

The minio service isn't running on localhost. The MINIO_HOST environment variable isn't used by the minio client. According to this documentation, you can provide a configuration in the MC_HOST_<hostname> environment variable.

Additionally, the way your create-bucket container is configured, it may start up and run before minio is ready to service requests, causing it to fail.

Bind mounts instead of docker volumes

Using a bind mount (./data:/data) instead of named volume is often sub-optimal because it leads to uid/gid conflicts between the host and container. Unless you really need to share the contents of that directory between the host and container, you're better off using a named volumethe contents of that directory between the host and container, you're better off using a named volume.


We can fix all of these issues with the following docker-compose.yaml:

services:
  minio:
    image: minio/minio:latest
    ports:
      - 9000:9000
      - 9001:9001
    volumes:
      - minio-data:/data
    environment:
      MINIO_ROOT_USER: $MINIO_ROOT_USER
      MINIO_ROOT_PASSWORD: $MINIO_ROOT_PASSWORD
    command: server /data --console-address :9001
    restart: unless-stopped

  create-bucket:
    image: minio/mc:latest
    environment:
      MC_HOST_minio: http://${MINIO_ROOT_USER}:${MINIO_ROOT_PASSWORD}@minio:9000
    entrypoint:
      - sh
      - -c
      - |
        until mc ls minio > /dev/null 2>&1; do
          sleep 0.5
        done

        mc mb minio/post-bucket

volumes:
  minio-data:

This assumes that you're setting MINIO_ROOT_USER and MINIO_ROOT_PASSWORD in your .env file, like this:

MINIO_ROOT_USER=admin
MINIO_ROOT_PASSWORD=minio-secret-key

The entrypoint script in the create-bucket container loops until minio is ready to service requests; then it creates the bucket.

Running docker-compose up with this configuration results in:

Creating network "container_default" with the default driver
Creating volume "container_minio-data" with default driver
Creating container_minio_1  ... done
Creating create-post-bucket ... done
Attaching to container_minio_1, create-post-bucket
minio_1          | Formatting 1st pool, 1 set(s), 1 drives per set.
minio_1          | WARNING: Host local has more than 0 drives of set. A host failure will result in data becoming unavailable.
minio_1          | MinIO Object Storage Server
minio_1          | Copyright: 2015-2023 MinIO, Inc.
minio_1          | License: GNU AGPLv3 <https://www.gnu.org/licenses/agpl-3.0.html>
minio_1          | Version: RELEASE.2023-06-02T23-17-26Z (go1.19.9 linux/amd64)
minio_1          |
minio_1          | Status:         1 Online, 0 Offline.
minio_1          | S3-API: http://192.168.192.2:9000  http://127.0.0.1:9000
minio_1          | Console: http://192.168.192.2:9001 http://127.0.0.1:9001
minio_1          |
minio_1          | Documentation: https://min.io/docs/minio/linux/index.html
minio_1          | Warning: The standard parity is set to 0. This can lead to data loss.
create-post-bucket | Bucket created successfully `minio/post-bucket`.
create-post-bucket exited with code 0

At this point, I can access the minio console as expected at http://localhost:9001 on my docker host.

huangapple
  • 本文由 发表于 2023年6月5日 00:43:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76401435.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定