Tôi có một ứng dụng với các dịch vụ sau:
web/- giữ và chạy một máy chủ web 3 bình python trên cổng 5000. Sử dụng sqlite3.worker/- có mộtindex.jstệp là một công nhân cho một hàng đợi. máy chủ web tương tác với hàng đợi này bằng API json qua cổng9730. Công nhân sử dụng redis để lưu trữ. Công nhân cũng lưu trữ dữ liệu cục bộ trong thư mụcworker/images/
Bây giờ câu hỏi này chỉ liên quan đến worker.
worker/Dockerfile
FROM node:0.12
WORKDIR /worker
COPY package.json /worker/
RUN npm install
COPY . /worker/
docker-compose.yml
redis:
image: redis
worker:
build: ./worker
command: npm start
ports:
- "9730:9730"
volumes:
- worker/:/worker/
links:
- redis
Khi tôi chạy docker-compose build, mọi thứ hoạt động như mong đợi và tất cả các mô-đun npm được cài đặt /worker/node_modulesnhư tôi mong đợi.
npm WARN package.json unfold@1.0.0 No README data
> phantomjs@1.9.2-6 install /worker/node_modules/pageres/node_modules/screenshot-stream/node_modules/phantom-bridge/node_modules/phantomjs
> node install.js
<snip>
Nhưng khi tôi làm docker-compose up, tôi thấy lỗi này:
worker_1 | Error: Cannot find module 'async'
worker_1 | at Function.Module._resolveFilename (module.js:336:15)
worker_1 | at Function.Module._load (module.js:278:25)
worker_1 | at Module.require (module.js:365:17)
worker_1 | at require (module.js:384:17)
worker_1 | at Object.<anonymous> (/worker/index.js:1:75)
worker_1 | at Module._compile (module.js:460:26)
worker_1 | at Object.Module._extensions..js (module.js:478:10)
worker_1 | at Module.load (module.js:355:32)
worker_1 | at Function.Module._load (module.js:310:12)
worker_1 | at Function.Module.runMain (module.js:501:10)
Hóa ra không có mô-đun nào có mặt /worker/node_modules(trên máy chủ hoặc trong thùng chứa).
Nếu trên máy chủ, tôi npm install, sau đó mọi thứ hoạt động tốt. Nhưng tôi không muốn làm điều đó. Tôi muốn container để xử lý các phụ thuộc.
Có chuyện gì ở đây vậy?
(Không cần phải nói, tất cả các gói đều nằm trong package.json.)
volumes: - worker/:/worker/khối khỏi docker-compose.ymltập tin. Dòng này ghi đè lên thư mục bạn thực hiện bằng lệnh COPY.
When I run docker-compose build, everything works as expected and all npm modules are installed in /worker/node_modules as I'd expect.- Làm thế nào bạn kiểm tra điều này?