【问题标题】:package in requirements.txt, but not seen in docker打包在 requirements.txt 中,但在 docker 中看不到
【发布时间】:2019-11-15 19:57:24
【问题描述】:

我有有效的 requirements.txt 文件,但 docker 没有安装要求中列出的软件包之一

Docker 版本 18.09.2 蟒蛇3.7.3

requirements.txt

django==2.2.2
celery==4.2.1
selenium==3.141.0
BeautifulSoup4==4.7.1
redis==3.2.0

Dockerfile

FROM python:3.7
ENV PYTHONUNBUFFERED 1
ENV DJANGO_ENV dev
ENV DJANGO_ENV dev
COPY ./requirements.txt /code/requirements.txt
RUN pip3 install --upgrade pip
RUN pip3 install -r /code/requirements.txt
COPY . /code/
WORKDIR /code/
EXPOSE 8000

docker_compose.yml

version: '3'

services:
  db:
    image: postgres:9.6.5
    volumes:
      - postgres_data:/var/lib/postgresql/data/
  redis:
    image: "redis:alpine"
  web:
    build: .
    command: bash -c "python /code/manage.py migrate --noinput && python /code/manage.py runserver 0.0.0.0:8000"
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db
      - redis
  celery:
    build: .
    command: celery -A google_scraper worker -l info
    volumes:
      - .:/code
    depends_on:
      - db
      - redis

volumes:
  postgres_data:

我尝试运行 celery 时的实际错误:

ImportError: Missing redis library (pip install redis)

当我为 docker 运行 bash 并通过手动 pip3 install redis 安装它时 - 它工作正常,但仍然不能解决构建它的问题,我不知道我在哪里犯了错误。

【问题讨论】:

  • 当你在docker中pip install redis时,安装的是哪个版本?
  • 3.2.0 但我尝试了不同的版本
  • 可能不是问题,但上面的文件名requirements.txt 有错字。
  • 是的,项目中没有错误——我正在修复它
  • 你确定基础镜像中安装了python-pip吗?

标签: python docker redis celery


【解决方案1】:

我想知道为什么 Docker 没有抱怨缺少 /code 目录?您确定 Docker 已成功构建映像吗?如果有,请向我解释COPY ./requirements.txt /code/requirements.txt 是如何工作的?我检查了,python:3.7 图像在其根文件系统中没有该目录...

【讨论】:

    猜你喜欢
    • 2017-11-08
    • 2023-01-19
    • 1970-01-01
    • 2016-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多