docker 无法连接Celery和Minio容器?

hwamh0ep  于 2023-08-03  发布在  Docker
关注(0)|答案(1)|浏览(120)

在我的Django应用程序中,我正在将上传视频的大小调整卸载给celery 工人。我还将所有媒体文件存储在Minio S3存储桶中。
调整大小进行得很顺利,没有任何错误,但是Celery无法连接到Minio容器。这是Celery的日志:

celery-worker_1  | [2023-07-19 20:51:46,076: INFO/MainProcess] Task common.tasks.resize_video[c38a90eb-793e-4190-a681-94b69eafadc8] received
celery-worker_1  | ffmpeg version 4.3.6-0+deb11u1 Copyright (c) 2000-2023 the FFmpeg developers
celery-worker_1  |   built with gcc 10 (Debian 10.2.1-6)
celery-worker_1  | ffmpeg version 4.3.6-0+deb11u1[tcp @ 0x55c7500727c0]  Copyright (c) 2000-2023 the FFmpeg developers Connection to tcp://localhost:9000 failed: Cannot assign requested address
celery-worker_1  | http://localhost:9000/event_media/test_video.mp4: Cannot assign requested address

字符串
问题是如何让Celery容器连接到http://minio:9000/而不是localhost?
下面是我使用的docker-compose.yml文件:

postgres:
    image: "postgres:14"
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=password
    volumes:
      - .:/opt/myapp
    ports:
      - "5432:5432"

  redis:
    image: redis:6
    ports:
      - "6379:6379"

  minio:
    image: minio/minio
    command: minio server /export
    ports:
      - "9000:9000"
    environment:
      - MINIO_ACCESS_KEY=dev_access
      - MINIO_SECRET_KEY=dev_secret

  celery-worker:
    build:
      context: .
      dockerfile: ./Dockerfile.celery
    env_file:
      - ./docker.dev.env
    environment:
      - CELERY_BROKER_URL=redis://redis:6379
      - CELERY_RESULT_BACKEND=redis://redis:6379
    depends_on:
      - redis
      - postgres
    command: celery -A myapp worker --loglevel INFO


以下是docker.dev.env文件的内容:

MINIO_STORAGE_ENDPOINT=minio:9000
MINIO_STORAGE_ACCESS_KEY=dev_access
MINIO_STORAGE_SECRET_KEY=dev_secret
MINIO_STORAGE_USE_HTTPS=False
MINIO_STORAGE_MEDIA_BUCKET_NAME=media-dev
MINIO_STORAGE_AUTO_CREATE_MEDIA_BUCKET=True
MINIO_STORAGE_MEDIA_URL=http://localhost:9000/
DEFAULT_FILE_STORAGE=minio_storage.storage.MinioMediaStorage


编辑:尝试更改

MINIO_STORAGE_MEDIA_URL=http://minio:9000/


这反而给了我以下错误:

celery-worker_1  | [http @ 0x55698dd429c0] HTTP error 403 Forbidden
celery-worker_1  | http://minio:9000/event_media/test_video.mp4: Server returned 403 Forbidden (access denied)


还在挠头呢

c86crjj0

c86crjj01#

在浏览了https://django-minio-storage.readthedocs.io/en/latest/usage/#django-settings-configuration的文档,特别是设置键MINIO_STORAGE_MEDIA_URL之后,我更新了docker.dev.env
起始

MINIO_STORAGE_MEDIA_URL=http://localhost:9000/

字符串

MINIO_STORAGE_MEDIA_URL=http://minio:9000/media-dev


我学到的是:

  1. localhost指向自己的容器,因此需要使用容器名称minio(如docker-compose.yml中定义的)。
  2. MINIO_STORAGE_MEDIA_URL应该 * 还 * 包含minio存储桶的名称,在本例中是MINIO_STORAGE_MEDIA_BUCKET_NAME定义的“media-dev”。

相关问题