使用带有docker-compose

时间:2016-10-25 08:54:04

标签: docker docker-compose node-sass

我目前正在使用docker并尝试使用docker-compose来运行我的应用程序:

Node-Backend: hapi
JS-Frontend:棱角分明
MongoDB 数据库

mongodb与docker结合使用。我在OSX计算机上开发并使用 node-sass 作为前端部分。在编写时出现错误:

server_1  |     Child extract-text-webpack-plugin:
server_1  |       + 1 hidden modules
server_1  |     
server_1  |     ERROR in Missing binding /app/node_modules/node-sass/vendor/linux-x64-48/binding.node
server_1  |     Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 6.x
server_1  |     
server_1  |     Found bindings for the following environments:
server_1  |       - OS X 64-bit with Node.js 6.x
server_1  |     
server_1  |     This usually happens because your environment has changed since running `npm install`.
server_1  |     Run `npm rebuild node-sass` to build the binding for your current environment.

node-sass 模块似乎需要linux绑定,但只是在容器内部有osx绑定。所以问题是:有没有一种聪明的方法来解决这个问题,即使开发过程仍然很舒服?

到目前为止,我还没有Dockerfile。但我的docker-compose.yml看起来像是:

version: '2'
services:
  server:
    image: node:6
    command: 'npm start'
    working_dir: '/app'
    volumes:
      - ./:/app
    depends_on:
      - mongo
    ports:
      - '1337:1337'
    environment:
      - NODE_ENV=prod
    links:
      - mongo:mongodb
  mongo:
    image: mongo:latest
    ports:
      - '127.0.0.1:27017:27017'
    volumes:
      - ./data/:/data/db

package.json

...

  "dependencies": {
    "accepts": "^1.3.3",
    "akaya": "^0.3.0",
    "angular": "^1.5.8",
    "angular-ui-router": "next",
    "bcrypt": "^0.8.7",
    "blipp": "^2.3.0",
    "boom": "^4.2.0",
    "emojilib": "^2.0.2",
    "emojione": "^2.2.6",
    "glue": "^4.0.0",
    "good": "^7.0.2",
    "good-console": "^6.1.2",
    "good-file": "^6.0.1",
    "good-squeeze": "^5.0.0",
    "hapi": "^15.2.0",
    "hapi-auth-basic": "^4.2.0",
    "hapi-auth-jwt2": "^7.1.3",
    "inert": "^4.0.2",
    "joi": "^9.2.0",
    "jquery": "^3.1.1",
    "jsonwebtoken": "^7.1.9",
    "lodash": "^4.16.4",
    "mongoose": "^4.6.4",
    "pm2": "^2.0.18",
    "twemoji": "^2.2.0",
    "wurst": "^0.9.1"
  },
  "devDependencies": {
    "autoprefixer": "^6.5.1",
    "babel-cli": "^6.16.0",
    "babel-core": "^6.17.0",
    "babel-eslint": "^7.0.0",
    "babel-loader": "^6.2.5",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-es2015": "^6.16.0",
    "babel-preset-stage-0": "^6.16.0",
    "baggage-loader": "^0.2.4",
    "chokidar": "^1.6.1",
    "clean-webpack-plugin": "^0.1.13",
    "copy-webpack-plugin": "^3.0.1",
    "css-loader": "^0.25.0",
    "eslint": "^3.8.1",
    "eslint-config-airbnb-base": "^9.0.0",
    "eslint-loader": "^1.6.0",
    "eslint-plugin-import": "^2.0.1",
    "extract-text-webpack-plugin": "^1.0.1",
    "file-loader": "^0.9.0",
    "html-loader": "^0.4.4",
    "html-webpack-plugin": "^2.24.0",
    "inline-style-prefix-all": "^2.0.2",
    "json-loader": "^0.5.4",
    "ng-annotate-loader": "^0.2.0",
    "ngtemplate-loader": "^1.3.1",
    "node-sass": "^3.10.1",
    "postcss-loader": "^1.0.0",
    "sass-loader": "^4.0.2",
    "style-loader": "^0.13.1",
    "url-loader": "^0.5.7",
    "webpack": "^1.13.2",
    "webpack-livereload-plugin": "^0.9.0",
    "webpack-manifest-plugin": "^1.1.0",
    "webpack-md5-hash": "^0.0.5"
  },
  "engines": {
    "node": "6.0.0",
    "npm": "^3.8.8"
  }

谢谢!

编辑:我的本地目录./被挂载到容器,因此我的OSX绑定模块也被挂载。是否有一种聪明的方法可以在容器内部执行新的npm i,而不会对开发过程有任何更大的限制?

3 个答案:

答案 0 :(得分:2)

您需要在容器内运行npm rebuild node-sass。您正在安装为OSX编译的二进制文件并尝试在Linux上运行。

答案 1 :(得分:1)

这可能是旧闻,但万一有其他人遇到这个......

在容器内运行npm install(为容器运行的环境构建绑定)

然后将绑定从node_modules/node-sass/vendor/复制到开发环境中。

我在Mac上为dev env执行此操作,但是在节点上执行此操作:alpine for running container。

答案 2 :(得分:0)

您应该编辑您的npm图像,在其中创建自己的运行public void ConfirmBtn_Click(object sender, EventArgs e) { string connString1 = "FirstConnectionSTring"; string connString2 = "SecondConnectionSTring"; ExecuteNonQuery(connString1); ExecuteNonQuery(connString2); } public void ExecuteNonQuery(string connString) { using (SqlConnection connection = new SqlConnection(connString)) { connection.Open(); SqlCommand cmd = new SqlCommand("DELETE FROM TABLE1 WHERE ID=@ID", connection); cmd.Parameters.AddWithValue("@ID", textbox1.Text); cmd.ExecuteNonQuery(); } } ,而不仅仅是npm install。因此容器内的npm包将与容器OS兼容。 您可以检查https://github.com/titouanfreville/SupJirallo(我没有使用node-sass,但它有一个带有npm install的节点映像)。