【问题标题】:Docker runs of "pip install" and "npm install" on same container overwriting each otherDocker 在同一容器上运行“pip install”和“npm install”,相互覆盖
【发布时间】:2015-11-09 11:36:09
【问题描述】:

在我的 docker 容器中,我正在尝试使用 pip 安装几个软件包以及通过 npm 安装 Bower。然而,似乎 pip 或 npm 中的任何一个先运行,/usr/local/bin 中的另一个内容都会被覆盖(具体来说,下面的 Dockerfile 中缺少 gunicorn,或者如果我交换 FROM..RUN 块的顺序,则缺少 Bower )。

这是 Docker 的预期行为吗?如果是,我该如何将我的 pip 包和 Bower 安装到同一目录 /usr/local/bin 中?

这是我的 Dockerfile:

FROM python:3.4.3
RUN mkdir /code
WORKDIR /code
ADD ./requirements/ /code/requirements/
RUN pip install -r /code/requirements/docker.txt
ADD ./ /code/

FROM node:0.12.7
RUN npm install bower

这是我的 docker-compose.yml 文件:

web:
  restart: always
  build: .
  expose:
    - "8000"
  links:
    - postgres:postgres
    #-redis:redis
  volumes:
    - .:/code
  env_file: .env
  command: /usr/local/bin/gunicorn myapp.wsgi:application -w 2 -b :8000 --reload

webstatic:
  restart: always
  build: .
  volumes:
    - /usr/src/app/static
  env_file: .env
  command: bash -c "/code/manage.py bower install && /code/manage.py collectstatic --noinput"

nginx:
  restart: always
  #build: ./config/nginx
  image: nginx
  ports:
    - "80:80"
  volumes:
    - /www/static
    - config/nginx/conf.d:/etc/nginx/conf.d
  volumes_from:
    - webstatic
  links:
    - web:web

postgres:
  restart: always
  image: postgres:latest
  volumes:
    - /var/lib/postgresql
  ports:
    - "5432:5432"

更新:我继续将此作为docker-compose issue 交叉发布,因为不清楚是否存在实际错误或我的配置是否有问题。我会不断更新这两个帖子,但如果您知道发生了什么,请随时发布。谢谢!

【问题讨论】:

  • 是拼写错误,还是ADD . /requirements /code/requirements/上有空格?
  • 错字;接得好。我会更新我的帖子。我想知道为什么 pip 继续安装每个“构建”。不幸的是,npm/pip 仍然存在同样的问题。

标签: docker npm pip docker-compose


【解决方案1】:

您不能在 Dockerfile 中使用多个 FROM 命令,也不能从 2 个不同的基础镜像创建镜像。因此,如果您需要在同一图像中使用 node 和 python,您可以将 node 添加到 python 图像或将 python 添加到 node 图像。

【讨论】:

  • 感谢您的信息。我想我现在对 Docker 和 Compose 有了更好的了解。您的帖子也将我带到了这个 other (closed) issue,其他人也有相同的用例,其他人提出了一些解决方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多