我有两个容器:应用程序和 MINIO
服务。
假设 docker-compose.yml
文件如下:
version: "3"
services:
s3:
image: minio/minio:RELEASE.2021-11-09T03-21-45Z
expose:
- "9000"
- "9001"
container_name: s3
command: server /data --console-address ":9001"
environment:
- MINIO_DOMAIN=s3
- MINIO_ROOT_USER=some_user
- MINIO_ROOT_PASSWORD=some_password
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
volumes:
- /tmp/data:/data
app:
image: my_image
container_name: app
build:
context: .
dockerfile: ./Dockerfile
depends_on:
- s3
app
容器通过 http://s3:9000
端点URL连接到 MINIO
当我运行时:
aws --profile myprof --endpoint-url="http://s3:9000" s3 ls s3://bucketname/path/to/file
一切都正常。
但是我应用程序
需要使用虚拟主机样式的路径,因此需要一些第三方库:
http://bucketname.s3:9000/path/to/file
当然,bucketname.s3
无法解析。
我尝试在 /etc/hosts
中设置 172.19.0.4 bucketname.s3
(容器本地 IP),一切正常。 但是我无法为每个新桶更新 /etc/hosts
。
所以,有没有办法在 Docker 中设置通配符主机名 *.s3
?
我的应用程序使用 python:3.7.0-alpine
镜像。
cat /etc/resolv.conf
的结果是:
nameserver 127.0.0.11
options edns0 ndots:0
看起来可以使用 Dockerfile
在本地主机解析服务中设置域名,有没有什么方法可以实现?
备忘录添加于2022/01/25
我将网络别名添加到 s3
容器作为临时解决方案,以便在 docker-compose up -d
时添加精确的存储桶名称,但这并不是一个解决方案,因为我仍然无法在不重启容器的情况下动态创建新的存储桶:
version: "3"
services:
s3:
image: minio/minio:RELEASE.2021-11-09T03-21-45Z
expose:
- "9000"
- "9001"
container_name: s3
command: server /data --console-address ":9001"
environment:
- MINIO_DOMAIN=s3
- MINIO_ROOT_USER=some_user
- MINIO_ROOT_PASSWORD=some_password
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
volumes:
- /tmp/data:/data
networks:
default:
aliases:
- bucketone.s3
- buckettwo.s3
我尝试在外部分离的 DNS 服务器中设置记录:
*.s3 IN CNAME s3.
但是这种方式也不起作用。看起来容器试图通过相同的DNS服务器解析,而不是使用Docker内部的DNS解析器(其中主机存在)。 因此,看起来唯一可能的解决方案是设置与Docker集成的DNS服务器,该服务器可以管理容器内部动态IP和记录。