2015-08-16 55 views
0

在我的碼頭容器中,我試圖用pip安裝幾個包,並通過npm安裝Bower。但似乎無論哪個pip或npm先運行,另一個在/ usr/local/bin中的內容都被覆蓋(具體來說,下面的Dockerfile缺少gunicorn,或者如果我交換我的FROM..RUN塊的順序,Bower就會丟失)。Docker在同一個容器上運行「pip install」和「npm install」互相覆蓋

這是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 

這裏是我的搬運工,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因爲如果現在還不清楚有一個實際的錯誤,或者如果我的配置是一個問題。我會保持這兩個帖子都更新,但如果您對發生的事情有所瞭解,也可以發帖。謝謝!

+1

這是一個錯字,還是在ADD中有一個空格。/requirements/code/requirements /'? – user2915097

+0

Typo;接得好。我會更新我的帖子。我想知道爲什麼PIP繼續與每個「構建」安裝。不幸的是,與npm/pip相同的問題。 –

回答

2

您不能在Dockerfile中使用多個FROM命令,並且無法從2個不同的基礎映像創建映像。所以,如果你需要在同一個圖像中的節點和Python,你可以添加節點到Python圖像或添加Python到節點圖像。

+0

感謝您的信息。我認爲我現在對Docker和Compose有了更好的理解。您的帖子也會將我帶到這個[其他(已關閉)問題](https://github.com/docker/docker/issues/3378),其他人有相同的使用案例,而其他人則提出了一些解決方法。 –