我在我的 docker-compose.yaml 文件中使用 minio/minio:latest 镜像,并且我希望 minio docker 容器拥有除 root 之外的用户。
检查了图像附带的 /usr/bin/docker-entrypoint.sh 后(见下文),我发现可以使用环境变量设置用户名和组:MINIO_USERNAME
和MINIO_GROUPNAME
。
但是我收到了以下错误:
minio | Time: 14:09:00 UTC 03/19/2024
minio | Error: unable to create (/data/.minio.sys/tmp) file access denied, drive may be faulty please investigate (*fmt.wrapError)
minio | 6: internal/logger/logger.go:260:logger.LogIf()
minio | 5: cmd/prepare-storage.go:96:cmd.bgFormatErasureCleanupTmp()
minio | 4: cmd/xl-storage.go:291:cmd.newXLStorage()
minio | 3: cmd/object-api-common.go:63:cmd.newStorageAPI()
minio | 2: cmd/format-erasure.go:706:cmd.initStorageDisksWithErrors.func1()
minio | 1: github.com/minio/pkg/[email protected]/sync/errgroup/errgroup.go:123:errgroup.(*Group).Go.func1()
minio | ERROR Unable to use the drive /data: file access denied: Invalid arguments specified
这是我的 docker-compose.yaml 文件:
---
services:
minio:
image: minio/minio:latest
container_name: minio
volumes:
- minio:/data
environment:
MINIO_USERNAME: ouss
MINIO_GROUPNAME: ouss
command: server /data
restart: always
volumes:
- minio
以及docker-entrypoint.sh
minio 镜像附带的
#!/bin/sh
#
# If command starts with an option, prepend minio.
if [ "${1}" != "minio" ]; then
if [ -n "${1}" ]; then
set -- minio "$@"
fi
fi
docker_switch_user() {
if [ -n "${MINIO_USERNAME}" ] && [ -n "${MINIO_GROUPNAME}" ]; then
if [ -n "${MINIO_UID}" ] && [ -n "${MINIO_GID}" ]; then
chroot --userspec=${MINIO_UID}:${MINIO_GID} / "$@"
else
echo "${MINIO_USERNAME}:x:1000:1000:${MINIO_USERNAME}:/:/sbin/nologin" >>/etc/passwd
echo "${MINIO_GROUPNAME}:x:1000" >>/etc/group
chroot --userspec=${MINIO_USERNAME}:${MINIO_GROUPNAME} / "$@"
fi
else
exec "$@"
fi
}
## DEPRECATED and unsupported - switch to user if applicable.
docker_switch_user "$@"