我需要一些Docker配置的幫助才能使Django在開發模式下使用webpack dev服務器。我想讓django docker容器訪問webpack生成的包。dockerized Django with webpackDevServer
我很努力地理解容器如何在docker-compose中與卷共享文件。
到目前爲止,我只設法有一個工作的Django dockerized應用程序,然後在本地運行npm install & & node server.js。
Dockerfile
# use base python image with python 2.7
FROM python:2.7
ENV PYTHONUNBUFFERED 1
# set working directory to /code/
RUN mkdir /code
WORKDIR /code
# add requirements.txt to the image
ADD requirements.txt /code/
# install python dependencies
RUN pip install -r requirements.txt
ADD . /code/
# Port to expose
EXPOSE 8000
泊塢窗,compose.yml
version: '2'
services:
db:
image: postgres
redis:
image: redis
rabbitmq:
image: rabbitmq:3-management
ports:
- "5672:5672" # we forward this port because it's useful for debugging
- "15672:15672" # here, we can access rabbitmq management plugin
worker:
build: .
command: celery worker -A example -l info
volumes:
- .:/code
links:
- db
- rabbitmq
- redis
web:
build:
context: .
dockerfile: Dockerfile
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
- ./assets/bundles:/webpack (here I'm trying in some way to address webpack files to assets/bundles)
ports:
- "8000:8000"
links:
- db
- rabbitmq
- redis
這是我嘗試用的WebPack
Dockerfile.webpack
FROM node:latest
WORKDIR /webpack
COPY package.json /webpack/
COPY server.js /webpack/
RUN npm config set registry http://registry.npmjs.org/ && npm install
ADD . /webpack/
# Port to expose
EXPOSE 3000
這是片段加到泊塢窗-compose.yml
webpack:
build:
context: .
dockerfile: Dockerfile.webpack
command: node server.js
volumes:
- .:/webpack
ports:
- "3000:3000"
server.js
var webpack = require('webpack')
var WebpackDevServer = require('webpack-dev-server')
var config = require('./webpack.config')
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
inline: true,
historyApiFallback: true
}).listen(3000, '0.0.0.0', function (err, result) {
if (err) {
console.log(err)
}
console.log('Listening at 0.0.0.0:3000')
})
我需要一些幫助。我對此感到沮喪。將容器的輸出(在本例中爲webpack)寫入到另一個容器(本例中爲web)可以訪問它的卷的正確方法是形成一個目錄(在本例中爲./code)。我試圖弄明白這一整天:/ – Pietro