我正试图将Vue.js + Nuxt.js应用程序包含在内。奇怪的是,当我运行docker run -p 3000:3000 <image_name>
时,我能够访问应用程序,但是当我运行docker-compose up命令时,我无法访问该应用程序。
我的Dockerfile如下所示:
FROM node:8.9.1-alpine
# Create app dir
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install deps
RUN apk update && apk upgrade && apk add git
COPY package*.json /usr/src/app/
RUN npm install
# If building for production:
# RUN npm install --only=production
COPY . /usr/src/app/
ENV HOST 0.0.0.0
EXPOSE 3000
# Start command
CMD [ "npm", "run", "dev" ]
如前所述,正在运行docker build -t <image_name> .
然后docker run -p 3000:3000 <image_name>
。
但是,使用以下docker-compose.yml文件:
version: '3'
services:
web:
build: .
ports:
- "3000:3000"
volumes:
- .:/usr/src/app
运行docker-compose up
会导致以下错误:
docker-compose up
Creating network "vueui_default" with the default driver
Creating vueui_web_1 ...
Creating vueui_web_1 ... done
Attaching to vueui_web_1
web_1 |
web_1 | > my-app@1.0.0 dev /usr/src/app
web_1 | > nuxt
web_1 |
web_1 | 2017-11-27T06:23:52.962Z nuxt:axios BaseURL: http://localhost:3000/api (Browser: /api)
web_1 | 2017-11-27T06:23:57.822Z nuxt:build App root: /usr/src/app
web_1 | 2017-11-27T06:23:57.823Z nuxt:build Generating /usr/src/app/.nuxt files...
web_1 | 2017-11-27T06:23:57.855Z nuxt:build Generating files...
web_1 | 2017-11-27T06:23:57.883Z nuxt:build Generating routes...
web_1 | 2017-11-27T06:23:58.018Z nuxt:build Building files...
web_1 | 2017-11-27T06:23:58.429Z nuxt:build Adding webpack middleware...
web_1 | ERROR Failed to compile with 3 errors06:24:28
web_1 |
web_1 | error in ./layouts/default.vue
web_1 |
web_1 | Module build failed: Error: Missing binding /usr/src/app/node_modules/node-sass/vendor/linux_musl-x64-57/binding.node
web_1 | Node Sass could not find a binding for your current environment: Linux/musl 64-bit with Node.js 8.x
web_1 |
web_1 | Found bindings for the following environments:
web_1 | - OS X 64-bit with Node.js 9.x
web_1 |
web_1 | This usually happens because your environment has changed since running `npm install`.
web_1 | Run `npm rebuild node-sass --force` to build the binding for your current environment.
web_1 | at module.exports (/usr/src/app/node_modules/node-sass/lib/binding.js:15:13)
web_1 | at Object.<anonymous> (/usr/src/app/node_modules/node-sass/lib/index.js:14:35)
web_1 | at Module._compile (module.js:635:30)
web_1 | at Object.Module._extensions..js (module.js:646:10)
web_1 | at Module.load (module.js:554:32)
web_1 | at tryModuleLoad (module.js:497:12)
web_1 | at Function.Module._load (module.js:489:3)
web_1 | at Module.require (module.js:579:17)
web_1 | at require (internal/module.js:11:18)
web_1 | at Object.<anonymous> (/usr/src/app/node_modules/sass-loader/lib/loader.js:3:14)
web_1 | at Module._compile (module.js:635:30)
web_1 | at Object.Module._extensions..js (module.js:646:10)
web_1 | at Module.load (module.js:554:32)
web_1 | at tryModuleLoad (module.js:497:12)
web_1 | at Function.Module._load (module.js:489:3)
web_1 | at Module.require (module.js:579:17)
web_1 |
web_1 | @ ./node_modules/vue-style-loader?{"sourceMap":true}!./node_modules/css-loader?{"minimize":true,"importLoaders":1,"sourceMap":true,"alias":{"/static":"/usr/src/app/static","/assets":"/usr/src/app/assets"}}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-314f53c6","scoped":false,"hasInlineConfig":true}!./node_modules/sass-loader/lib/loader.js?{"indentedSyntax":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0&bustCache!./layouts/default.vue 4:14-499 13:3-17:5 14:22-507
web_1 | @ ./layouts/default.vue
web_1 | @ ./node_modules/babel-loader/lib?{"babelrc":false,"cacheDirectory":true,"presets":["/usr/src/app/node_modules/babel-preset-vue-app/dist/index.common.js"]}!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./.nuxt/App.vue
web_1 | @ ./.nuxt/App.vue
web_1 | @ ./.nuxt/index.js
web_1 | @ ./.nuxt/client.js
web_1 | @ multi webpack-hot-middleware/client?name=client&reload=true&timeout=3000&path=/__webpack_hmr ./.nuxt/client.js
web_1 |
web_1 | error in ./layouts/plain.vue
web_1 |
web_1 | Module build failed: Error: Missing binding /usr/src/app/node_modules/node-sass/vendor/linux_musl-x64-57/binding.node
web_1 | Node Sass could not find a binding for your current environment: Linux/musl 64-bit with Node.js 8.x
web_1 |
web_1 | Found bindings for the following environments:
web_1 | - OS X 64-bit with Node.js 9.x
web_1 |
web_1 | This usually happens because your environment has changed since running `npm install`.
web_1 | Run `npm rebuild node-sass --force` to build the binding for your current environment.
web_1 | at module.exports (/usr/src/app/node_modules/node-sass/lib/binding.js:15:13)
web_1 | at Object.<anonymous> (/usr/src/app/node_modules/node-sass/lib/index.js:14:35)
web_1 | at Module._compile (module.js:635:30)
web_1 | at Object.Module._extensions..js (module.js:646:10)
web_1 | at Module.load (module.js:554:32)
web_1 | at tryModuleLoad (module.js:497:12)
web_1 | at Function.Module._load (module.js:489:3)
web_1 | at Module.require (module.js:579:17)
web_1 | at require (internal/module.js:11:18)
web_1 | at Object.<anonymous> (/usr/src/app/node_modules/sass-loader/lib/loader.js:3:14)
web_1 | at Module._compile (module.js:635:30)
web_1 | at Object.Module._extensions..js (module.js:646:10)
web_1 | at Module.load (module.js:554:32)
web_1 | at tryModuleLoad (module.js:497:12)
web_1 | at Function.Module._load (module.js:489:3)
web_1 | at Module.require (module.js:579:17)
web_1 |
web_1 | @ ./node_modules/vue-style-loader?{"sourceMap":true}!./node_modules/css-loader?{"minimize":true,"importLoaders":1,"sourceMap":true,"alias":{"/static":"/usr/src/app/static","/assets":"/usr/src/app/assets"}}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-1215e3b4","scoped":false,"hasInlineConfig":true}!./node_modules/sass-loader/lib/loader.js?{"indentedSyntax":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0&bustCache!./layouts/plain.vue 4:14-497 13:3-17:5 14:22-505
web_1 | @ ./layouts/plain.vue
web_1 | @ ./node_modules/babel-loader/lib?{"babelrc":false,"cacheDirectory":true,"presets":["/usr/src/app/node_modules/babel-preset-vue-app/dist/index.common.js"]}!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./.nuxt/App.vue
web_1 | @ ./.nuxt/App.vue
web_1 | @ ./.nuxt/index.js
web_1 | @ ./.nuxt/client.js
web_1 | @ multi webpack-hot-middleware/client?name=client&reload=true&timeout=3000&path=/__webpack_hmr ./.nuxt/client.js
web_1 |
web_1 | error in ./layouts/public.vue
web_1 |
web_1 | Module build failed: Error: Missing binding /usr/src/app/node_modules/node-sass/vendor/linux_musl-x64-57/binding.node
web_1 | Node Sass could not find a binding for your current environment: Linux/musl 64-bit with Node.js 8.x
web_1 |
web_1 | Found bindings for the following environments:
web_1 | - OS X 64-bit with Node.js 9.x
web_1 |
web_1 | This usually happens because your environment has changed since running `npm install`.
web_1 | Run `npm rebuild node-sass --force` to build the binding for your current environment.
web_1 | at module.exports (/usr/src/app/node_modules/node-sass/lib/binding.js:15:13)
web_1 | at Object.<anonymous> (/usr/src/app/node_modules/node-sass/lib/index.js:14:35)
web_1 | at Module._compile (module.js:635:30)
web_1 | at Object.Module._extensions..js (module.js:646:10)
web_1 | at Module.load (module.js:554:32)
web_1 | at tryModuleLoad (module.js:497:12)
web_1 | at Function.Module._load (module.js:489:3)
web_1 | at Module.require (module.js:579:17)
web_1 | at require (internal/module.js:11:18)
web_1 | at Object.<anonymous> (/usr/src/app/node_modules/sass-loader/lib/loader.js:3:14)
web_1 | at Module._compile (module.js:635:30)
web_1 | at Object.Module._extensions..js (module.js:646:10)
web_1 | at Module.load (module.js:554:32)
web_1 | at tryModuleLoad (module.js:497:12)
web_1 | at Function.Module._load (module.js:489:3)
web_1 | at Module.require (module.js:579:17)
web_1 |
web_1 | @ ./node_modules/vue-style-loader?{"sourceMap":true}!./node_modules/css-loader?{"minimize":true,"importLoaders":1,"sourceMap":true,"alias":{"/static":"/usr/src/app/static","/assets":"/usr/src/app/assets"}}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-1eea6a3d","scoped":false,"hasInlineConfig":true}!./node_modules/sass-loader/lib/loader.js?{"indentedSyntax":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0&bustCache!./layouts/public.vue 4:14-498 13:3-17:5 14:22-506
web_1 | @ ./layouts/public.vue
web_1 | @ ./node_modules/babel-loader/lib?{"babelrc":false,"cacheDirectory":true,"presets":["/usr/src/app/node_modules/babel-preset-vue-app/dist/index.common.js"]}!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./.nuxt/App.vue
web_1 | @ ./.nuxt/App.vue
web_1 | @ ./.nuxt/index.js
web_1 | @ ./.nuxt/client.js
web_1 | @ multi webpack-hot-middleware/client?name=client&reload=true&timeout=3000&path=/__webpack_hmr ./.nuxt/client.js
知道我可能做错了什么吗?
提前致谢!
修改
我正在使用MacOS进行本地开发,所以我想也许模块可能会以某种方式受到影响(因此消息OS X 64-bit with Node.js 9.x
)。但是,我的.dockerignore
中有以下内容,所以不应该是这样的:
node_modules
npm-debug.log
答案 0 :(得分:1)
我能解决这个问题。正如其他线程所提到的,问题是需要在容器中执行以下命令:
npm rebuild node-sass
这是因为我的本地开发环境(MacOS)和Docker容器(Linux)存在差异。
由于默认情况下bash不存在于alpine中,因此可以通过使用以下命令放入容器来完成:
docker exec -it <image_name> /bin/sh