2016年9月17日 星期六

docker on AWS EB

為什麼要摸Docker
1.AWS EB node 環境,有無止境的相依性問題
git clone react-starter-kit
eb init
eb create
git add * (without node_module)
git commit -m
eb deploy
eb open <=(should be OK? but!  -> logs...)

2.所以Docker
AWS ECS = Docker + EB(scale .... load balancing ...)
神聖的AWS開創出,神奇的ECS(private images..)
ECS task ... ≠ Docker
ECS <= Docker Compose (YAML) <=?..
前因後果加demo.

install on ec2
http://www.ybrikman.com/writing/2015/11/11/running-docker-aws-ground-up/

教學
https://ap-southeast-1.console.aws.amazon.com/ec2/v2/home?region=ap-southeast-1#V2CreateELBWizard:
https://nodejs.org/en/docs/guides/nodejs-docker-webapp/



command : aws ecr get-login --region ap-southeast-1

docker push 897420788211.dkr.ecr.ap-southeast-1.amazonaws.com/images:latest
command : ecs-cli

==========================然後還是搞不定=============
最後原來 EB 支援 Docker

 package.json 
{
  "name": "docker_web_app",
  "version": "1.0.0",
  "description": "Node.js on Docker",
  "author": "First Last <first.last@example.com>",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^4.13.3"
  }
}

server.js 
'use strict';

const express = require('express');

// Constants
const PORT = 8080;

// App
const app = express();
app.get('/', function (req, res) {
  res.send('Fucker world\n');
});

app.listen(PORT);
console.log('Running on http://localhost:' + PORT);

Dockerfile

FROM node:argon
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 8080
CMD [ "npm", "start" ]

eb init ... 都一樣

======完成====


再來要自訂自已的image
所以要上傳 ECR
aws ecr get-login
會回傳一大堆 copy paste 再執行 就可以傳上去了
DockerFile
怎麼將本機端的image傳到 ecr ,然後再 Dockfile 來用




沒有留言:

張貼留言