2017年2月14日 星期二

解 dokcer nodejs "ENOENT: no such file or directory, uv_cwd" issue.

可能是docker 內部的神奇部份,
所以只要 node app.js 跟 node ./app.js or node ../app/app.js
每個docker node 錯開 啟使,就正常了

2017年2月11日 星期六

aws multi docker 心得

每次重啟,每一個docker container 的資料會清空,記得要加上volume到外部的folder,才能保存資料。

Dockerrun.aws.json 的 environment 的設定方式

"environment": [
        {
          "name":"PORT",
          "value":"1337"
        },
        {
          "name":"DATABASE_URI",
          "value":"mongodb://mongo:27017/test"
        },
        {
          "name":"APP_ID",
          "value":"test"
        },
        {
          "name":"MASTER_KEY",
          "value":"test_MASTER_KEY"
        },
        {
          "name":"JAVASCRIPT_KEY",
          "value":"test_JAVASCRIPT_KEY"
        }

     
      ]

2017年2月10日 星期五

aws eb multi docker Dockerrun.aws.json

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_v2config.html

{
  "AWSEBDockerrunVersion": 2,
  "volumes": [
    {
      "name": "app",
      "host": {
        "sourcePath": "/var/app/current/app"
      }
    },

    {
      "name": "nginx-proxy-conf",
      "host": {
        "sourcePath": "/var/app/current/proxy/conf.d"
      }
    },
    {
      "name": "mongo"
    },
    {
      "name": "parse-server"
    }
  ],
  "containerDefinitions": [
    {
      "name": "app",
      "image": "node:latest",
      "essential": true,
      "memory": 256, //不能太少,會 npm install 失敗
      "command": [
        "/bin/bash",
        "/usr/src/app/run-dev.sh"
      ],
      "portMappings": [
        {
          "hostPort": 3000,
          "containerPort": 3000
        }
      ],
      "mountPoints": [
        {
          "sourceVolume": "app",
          "containerPath": "/usr/src/app"
        }
      ]
    },

    {
      "name":"mongo",
      "image":"mongo",
      "essential": true,
      "memory": 128,
      "portMappings": [
        {
          "hostPort": 27017,
          "containerPort": 27017
        }
      ]

    },
    {
      "name": "parse-server",
      "image": "yongjhih/parse-server",
      "essential": true,
      "memory": 256,
      "portMappings": [
        {
          "hostPort": 1337,
          "containerPort": 1337
        }
      ],
      "mountPoints": [
        {
          "sourceVolume": "app",
          "containerPath": "/usr/src/app"
        }
      ],
      "links": [
        "mongo"
      ],
      "environment": [
        {
          "name":"parse-server",
          "PORT": "1337",
          "DATABASE_URI":"mongodb://mongo:27017/test",
          "APP_ID":"test",
          "MASTER_KEY":"test_MASTER_KEY",
          "JAVASCRIPT_KEY":"test_JAVASCRIPT_KEY"

        }
      ]
    },
 
    {
      "name": "nginx-proxy",
      "image": "nginx",
      "essential": true,
      "memory": 128,
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 80
        }
      ],
      "links": [
        "parse-server",
        "mongo",
        "app"
      ],
      "mountPoints": [
        {
          "sourceVolume": "awseb-logs-nginx-proxy",
          "containerPath": "/var/log/nginx"
        },
        {
          "sourceVolume": "nginx-proxy-conf",
          "containerPath": "/etc/nginx/conf.d",
          "readOnly": true
        }
      ]
    }

  ]
}

2017年2月8日 星期三

multi docker nginx + nodejs 心得


  1. 用nginx prxoy 可以mapping到不同的image,但外部可以持續用相同的cookie . 
  2. 多專案debug時,直接用內網ip做 proxy_pass就可以了
  3. 用docker-compose做 multi docker,做link後,所有的port都不需要開到外部去,增加安全性.



server {
listen 80;
server_name localhost;
location /test {
proxy_pass http://app:3000/test; # proxy_pass http://192.168.1.100:3000/test;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location / {
proxy_pass http://app2:3001; # proxy_pass http://192.168.1.100:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /parse {
proxy_pass http://parse-server:1337/parse; # proxy_pass http://192.168.1.100:1337/parse;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
} docker-compose.yml <
version: '2'
services:
app:
image: "node:latest"
working_dir: /usr/src/app
command: ./run-dev.sh
volumes:
- ./app:/usr/src/app
environment:
- port=3000
depends_on:
- parse-server
app2:
image: "node:latest"
working_dir: /usr/src/app
command: ./run-dev.sh
volumes:
- ./app:/usr/src/app
environment:
- port=3001
depends_on:
- parse-server
mongo:
image: "mongo"
parse-server:
image: yongjhih/parse-server
# ports:
# - "1337:1337"
environment:
PORT: 1337
DATABASE_URI: "mongodb://mongo:27017/test"
APP_ID: "test"
MASTER_KEY: test_MASTER_KEY
JAVASCRIPT_KEY: test_JAVASCRIPT_KEY
links:
- mongo
depends_on:
- mongo
nginx:
image: nginx
ports:
- "5010:80"
volumes:
- ./proxy/conf.d:/etc/nginx/conf.d
links:
- parse-server
- mongo
- app
- app2

2017年2月7日 星期二

docker nginx 連外面的localhost port

 proxy_pass          http://192.168.1.108:3000/;
直接mapping 內網ip

2017年2月6日 星期一

2017年2月2日 星期四

解injectTapEventPlugin.js 錯誤 ,不要用yarn 用npm install

ERROR in ./~/react-tap-event-plugin/src/injectTapEventPlugin.js
Module not found: Error: Cannot resolve module 'react-dom/lib/EventPluginHub' in /Users/chienhunglin/Dropbox/c
hatbot/web-platform/node_modules/react-tap-event-plugin/src
 @ ./~/react-tap-event-plugin/src/injectTapEventPlugin.js 23:2-41

ERROR in ./~/react-tap-event-plugin/src/TapEventPlugin.js
Module not found: Error: Cannot resolve module 'react-dom/lib/EventConstants' in /Users/chienhunglin/Dropbox/c
hatbot/web-platform/node_modules/react-tap-event-plugin/src
 @ ./~/react-tap-event-plugin/src/TapEventPlugin.js 22:21-60

ERROR in ./~/react-tap-event-plugin/src/TapEventPlugin.js
Module not found: Error: Cannot resolve module 'react-dom/lib/EventPluginUtils' in /Users/chienhunglin/Dropbox
/chatbot/web-platform/node_modules/react-tap-event-plugin/src
 @ ./~/react-tap-event-plugin/src/TapEventPlugin.js 23:23-64

ERROR in ./~/react-tap-event-plugin/src/TapEventPlugin.js
Module not found: Error: Cannot resolve module 'react-dom/lib/EventPropagators' in /Users/chienhunglin/Dropbox
/chatbot/web-platform/node_modules/react-tap-event-plugin/src
 @ ./~/react-tap-event-plugin/src/TapEventPlugin.js 24:23-64

ERROR in ./~/react-tap-event-plugin/src/TapEventPlugin.js
Module not found: Error: Cannot resolve module 'react-dom/lib/SyntheticUIEvent' in /Users/chienhunglin/Dropbox
/chatbot/web-platform/node_modules/react-tap-event-plugin/src
 @ ./~/react-tap-event-plugin/src/TapEventPlugin.js 25:23-64

ERROR in ./~/react-tap-event-plugin/src/TapEventPlugin.js
Module not found: Error: Cannot resolve module 'react-dom/lib/ViewportMetrics' in /Users/chienhunglin/Dropbox/
chatbot/web-platform/node_modules/react-tap-event-plugin/src
 @ ./~/react-tap-event-plugin/src/TapEventPlugin.js 27:22-62

https://github.com/zilverline/react-tap-event-plugin/issues/93
用npm install