卷未安装在Nginx容器中 [英] volume not getting mounted in nginx container

查看:82
本文介绍了卷未安装在Nginx容器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的撰写文件,该文件可以启动2个容器

I have the below compose file which starts 2 containers

services:
  nginx:
    container_name: nginx
    build: ./nginx/
    ports:
      - "80:80"
    links:
      - node:node
    volumes_from:
      - node

  node:
    container_name: node
    build: .
    env_file: .env

    command: npm run package

节点的dockerfile

The dockerfile for node

FROM node:6.0

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install

# Bundle app source
COPY . /usr/src/app

EXPOSE 8000

docker-compose up似乎没有将节点卷挂载到nginx中.我需要该卷来提供来自节点的静态文件

docker-compose up doesnt seem to mount the node volumes into nginx. I require the volume to serve the static files from node

location / {
    #The location setting lets you configure how nginx responds to requests for resources within the server.
    proxy_pass http://node:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location ~* \.(js|css|png|jpeg)$ {
  root /usr/src/app/public;
  expires 30d;
}

该卷存在于节点中

avernus@avernus-VirtualBox:~$ docker exec -it node bash
root@127bddea4e31:/usr/src/app# ls                                                                                                            
Dockerfile  docker-compose.override.yml  migrations    postgres-test  shared         webpack.config.js
Makefile    docker-compose.prod.yml  node_modules  public         socketcluster  webpack.production.config.js
client      docker-compose.yml       package.json  server         test

但是Nginx似乎没有卷

But Nginx doesnt seem to have the volumes

avernus@avernus-VirtualBox:~$ docker exec -it nginx bash
root@47ca17fac4b3:/# cd /usr/src/app                                                                                                          
bash: cd: /usr/src/app: No such file or directory

还有其他我想念的东西吗?

Is there something else i'm missing?

推荐答案

docker-compose.yml的节点部分未声明任何卷-docker如何知道应该共享节点映像的哪一部分!尝试将类似的内容添加到您撰写的Yaml中的节点服务中:

The node part of your docker-compose.yml doesn't declare any volumes - how should docker know which part of your node image should be shared! Try adding something like this to the node service in your compose yaml:

volumes:
  - /usr/src/app

这篇关于卷未安装在Nginx容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆