卷未安装在nginx容器中

时间:2016-08-24 15:23:03

标签: node.js nginx docker

我有以下撰写文件,它启动2个容器

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

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中。我要求卷为节点

中的静态文件提供服务
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似乎没有音量

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

我还缺少其他东西吗?

1 个答案:

答案 0 :(得分:2)

docker-compose.yml的节点部分未声明任何卷 - docker应该如何知道应该共享节点映像的哪个部分!尝试将这样的内容添加到compose yaml中的节点服务中:

volumes:
  - /usr/src/app