免責聲明

Disclaimer (免責聲明)
繼續閱覽代表您接受以上的免責聲明.
To continue reading means you accept the above disclaimer.

2015年2月25日 星期三

ppk to pem


//===
http://www.ramsmusings.com/2014/02/20/converting-a-putty-ppk-file-to-a-pem-file-for-accessing-aws-ec2-instances/

> puttygen ssh1.ppk -O private-openssh -o ssh1.pem

or

use puttygen gui -> load .ppk file -> 'conversion' tab

2015年2月22日 星期日

fig.yml for docker


//=== http://www.fig.sh
install fig ( Fast, isolated development environments using Docker )

$ sudo curl -L https://github.com/docker/fig/releases/download/1.0.1/fig-`uname -s`-`uname -m` > /usr/local/bin/fig; chmod +x /usr/local/bin/fig
or
$ sudo pip install -U fig [ as a Python package ]

$ fig --version


//=== http://www.fig.sh/yml.html

example fig.yml to build two docker images
[
. is the cwd(current working directory) where fig.yml is located;
./mywebApp is the nodejs app folder where a Dockerfile must exist to build docker image;
./mydb is the database folder where a Dockerfile must exist to build docker image;
]

*** .dockerignore file cannot include 'Dockerfile' !!!
otherwise, fig build will fail with message 'Can't build a directory with no Dockerfile'
although docker build still succeed.


web:
build: ./mywebApp/
command: node app.js
volumes:
- ./mywebApp:/usr/src/app
links:
- db:db_alias
ports:
- "80:3000"

db:
build: ./mydb/
ports:
- "27017:27017"




-->
$ fig rm [ removes containers ]
$ fig build [ rebuild images ]
$ fig up [ run whole setup again ]




*** https://github.com/docker/fig/issues/832

[the correct format]
volumes:
- ./mywebApp:/usr/src/app


[the wrong format]
volumes:
- ./mywebApp: /usr/src/app
the white space after ':' will fail the build




//===
more fig.yml examples for docker
http://blog.docker.com/tag/fig/
http://www.syncano.com/docker-workflow-fig-sh/

"""...
Fig is a python application that helps you run groups of docker containers.

...
The docker command line interface is awesome, but if you start working with
many containers at once and link them in the development environment,
typing the commands into the command line gets burdensome.

...
The most pragmatic approach to this problem is creating a bash script ...
..."""

--> use 'fig' to simplify the co-working of multiple containers.


2015年2月13日 星期五

docker, CMD, EntryPoint


//=== http://stackoverflow.com/questions/21553353/what-is-the-difference-between-cmd-and-entrypoint-in-a-dockerfile

"""...
Docker has a default entrypoint which is /bin/sh -c but does not have a default command.
...
When you run docker like this: docker run -i -t ubuntu bash
... the actual thing that gets executed is /bin/sh -c bash.

... docker run -i -t ubuntu. You will still start a bash shell in the container
because of the ubuntu Dockerfile specified a default CMD: CMD ["bash"] ...

... docker run redisimg redis -H something -u toto get key, you can simply have
ENTRYPOINT ["redis", "-H", "something", "-u", "toto"] and then
... docker run redisimg get key.


..."""



2015年2月12日 星期四

Dockering nodejs and mongodb on EC2 ubuntu


(one host, two containers) scenario
(one ubuntu host, nodejs container + mongodb container)

//=== Official repo for nodejs on docker
https://registry.hub.docker.com/_/node/

[Dockerfile for myapp]
$ cd myapp
$ nano Dockerfile

FROM node:0.10-onbuild
EXPOSE 8080 [can be omitted?]

[build myapp image based on node:0.10?]
$ sudo docker build -t myapp .



//=== Official repo for mongodb on docker
https://registry.hub.docker.com/_/mongo/

[prerequisites]
* from https://github.com/docker-library/mongo/blob/d9fb48dbdb0b9c35d35902429fe1a28527959f25/2.2/Dockerfile
we can guess /data/db is where mongodb stores data;

* mydb.ns and mydb.0 are the data files of mongodb for myapp
copy them to local folder mymongo to build image based on Official repo mongo:2.2


[Dockerfile for mymong]
$ cd mymongo
$ nano Dockerfile

FROM mongo:2.2
Maintainer 3h
COPY mydb.ns /data/db/mydb.ns
COPY mydb.0 /data/db/mydb.0

$ sudo docker build -t mymongo .



//=== start mymongo first, then start myapp

http://blog.giantswarm.io/getting-started-with-docker-and-meanjs
[start mymongo with container named 'db']
$ sudo docker run -p 27017:27017 -d --name db mymongo


https://docs.docker.com/userguide/dockerlinks/
[start myapp with link to the running 'db' container via alias named 'mydb_alias']
$ sudo docker run -p 80:3000 --link db:mydb_alias myapp

* port 80 is for ubuntu host so that internet users can access my app;
* port 3000 is for container, which should match that used in app.js for nodejs


*** the alias name for db host, 'mydb_alias' should match that used in app.js for nodejs
ie. to establish db connection via
db host: mydb_alias
db port: 27017


//=== test mongod on docker container

[ start up mongod container ]
$ sudo docker run -p 0.0.0.0:27017:27017 -d --name db mongo:2.2
or
$ sudo docker run -p l27.0.0.1:27017:27017 -d --name db mongo:2.2
or
$ sudo docker run -p localhost:27017:27017 -d --name db mongo:2.2


[install mongo client tool]
$ sudo apt-get install mongodb-clients
$ mongo
...
>


2015年2月11日 星期三

docker + mongodb


//=== http://cloud-mechanic.blogspot.com/2014/08/docker-simple-service-container-example.html
Dockerfile:
VOLUME [ "/var/lib/mongodb" ]

""" ...
declares that the directory /var/lib/mongodb will be used as a mountpoint for external storage.

... """


//=== https://docs.docker.com/examples/mongodb/
""" ...
# Usage: sudo docker run --name -d /
$ sudo docker run --name mongo_instance_001 -d my/repo

...
# Usage: sudo docker run --name -d / --noprealloc --smallfiles
$ sudo docker run --name mongo_instance_001 -d my/repo --noprealloc --smallfiles

...
# Usage: sudo docker logs
$ sudo docker logs mongo_instance_001

...
# Usage: mongo --port
$ mongo --port 12345


... """



//=== https://docs.docker.com/userguide/dockerlinks/

""" ...
$ sudo docker run -d -P training/webapp python app.py
...
the -P flag was used to automatically map any network ports inside it to a random high port from the range 49153 to 65535 on our Docker host. Next, when docker ps was run, you saw that port 5000 in the container was bound to port 49155 on the host.
...
$ sudo docker ps nostalgic_morse
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bc533791f3f5 training/webapp:latest python app.py 5 seconds ago Up 2 seconds 0.0.0.0:49155->5000/tcp nostalgic_morse
...
bind a container's ports to a specific port using the -p flag:
$ sudo docker run -d -p 5000:5000 training/webapp python app.py
...

By default the -p flag will bind the specified port to all interfaces on the host machine. But you can also specify a binding to a specific interface, for example only to the localhost.
$ sudo docker run -d -p 127.0.0.1:5000:5000 training/webapp python app.py
...
if you've bound the container port to the localhost on the host machine, then the docker port output will reflect that.
$ sudo docker port nostalgic_morse 5000
127.0.0.1:49155
...

use docker inspect to return the container's name.
$ sudo docker inspect -f "{{ .Name }}" aed84ee21bde
/web
...

The --link flag takes the form:
--link :alias
...

... """


[run mongod from repo:tag= mongo:2.2 ]
$ sudo docker run -d --name db mongo:2.2

[start a container from image myapp:mytag and link to mongodb container named 'db' with alias 'db_1']
$ sudo docker run -p 3000:3000 --link db:db_1 myapp:mytag


""" ...
inspect your linked containers with docker inspect:

$ sudo docker inspect -f "{{ .HostConfig.Links }}" myapp:mytag
[/db:/web/db]

... """

2015年2月5日 星期四

docker install on EC2 ubuntu


[ref]
http://www.openfoundry.org/tw/tech-column/9319-docker-101

https://docs.docker.com/installation/amazon/
https://docs.docker.com/installation/ubuntulinux/
https://docs.docker.com/userguide/

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-getting-started

docker networking problem
https://blog.codecentric.de/en/2014/01/docker-networking-made-simple-3-ways-connect-lxc-containers/




//=== install docker on ec2 ubuntu

https://docs.docker.com/installation/amazon/

""" ...
There are several ways to install Docker on AWS EC2.
You can use Amazon Linux, which includes the Docker packages in its Software Repository,
or ...
...
for example a Standard Ubuntu Installation.
... """




//=== to install docker on Ubuntu14 is easier than Ubuntu12

$ sudo apt-get update
$ sudo apt-get install docker.io

$ sudo docker info
Containers: 0
Images: 0
...

*** after install docker.io
having docker installed, in general we shall have the
docker daemon running in the background.
If not, run the docker daemon:

$ sudo docker -d &



//===
??? to enable tab-completion of Docker commands in BASH,
either restart BASH or:
$ source /etc/bash_completion.d/docker.io



//== login docker.com
$ sudo docker login
Username: [ENTER YOUR USERNAME]
Password:
Email: [ENTER YOUR EMAIL]
Login Succeeded

$ sudo docker run centos:centos6 /bin/date
$ sudo docker run -t -i centos:centos6 bash
[ centos:centos6 === repo_name:tag ]


$ sudo docker search centos
[find out repos with keyword 'centos']

-->
# whoami
# w


--> to close the container
# exit
or
# Ctrl + D,

--> to leave the container tty shell [container still run in background]
# Ctrl + P then Ctrl + Q

ctl+p then ctl+q



//=== after going back to the host ubuntu shell
$ sudo docker ps [show the running containers]
$ sudo docker ps -a [show containers history]
$ sudo docker images [show images, 'image' : the committed container snapshot]
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos centos6 70441cac1ed5 3 weeks ago 215.8 M
...



--> to resume to the running container
$ sudo docker exec -t -i 0f83f1728262 bash
[0f83f1728262 is the container_id]

Error: Command not found: exec

-->
http://askubuntu.com/questions/581234/docker-exec-command-is-not-working
""" docker exec command will support in new versions only.(>1.3) """

-->
Try docker attach

$ sudo docker attach container_id
[enter again?]


[rm container]
$ sudo docker rm 0f83f1728262
0f83f1728262



//=== -v mount point inside the container
sudo docker run -t -i -v /myData centos:centos6 bash


//=== -v [HOST_DIR]:[CONTAINER_DIR]
mount folder on host OS to the mount point inside the container


[ex]
host folder: /home/uuu13/docker/try1/
mount point in container: /myApp

$ sudo docker run -t -i -v /home/uuu13/docker/try1/:/myApp reponame bash



//===
$ sudo docker search php

$ sudo docker pull tutum/apache-php [dnload repo image]
Pulling repository tutum/apache-php
...


//===
$ sudo docker run -t -i tutum/apache-php bash
[ create a new container from repo 'tutum/apache-php'
and open an interactive tty with bash shell ]


""" ...
Container 內 PHPUnit 安裝(示範用):

root@aeeb1980c96e:/app# apt-get update
root@aeeb1980c96e:/app# apt-get install wget php5-xdebug
root@aeeb1980c96e:/app# cd /usr/local/bin ; \
> wget https://phar.phpunit.de/phpunit.phar
root@aeeb1980c96e:/usr/local/bin# chmod +x phpunit.phar
root@aeeb1980c96e:/usr/local/bin# mv phpunit.phar \
> phpunit
root@aeeb1980c96e:/usr/local/bin# exit
[離開 container...]

目前,我們已經建立一個新的 container,container ID 為 aeeb1980c96e 。
... """


""" ...
$ sudo docker commit -m="Add PHPUnit and xdebug" \
> -a="Huang Yi-Ming" aeeb1980c96e \
> ymhuang0808/phpunit-testing:php5.5.9

ymhuang0808/phpunit-testing ...
通常斜線( / )前面為在 Docker Hub 的帳號名稱(前面部分有註冊 Docker Hub 帳號),後面則是 repo 名稱.
php5.5.9:tag 名稱,
... """





//===
$ sudo docker search angular
$ sudo docker pull florentbenoit/docker-angularjs-tutorials


*** https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-getting-started
""" ...
Remember that with docker, commits are cheap.
Do not hesitate to use them to create images to save your progress with a
container or to roll back when you need (e.g. like snapshots in time).
... """



//=== https://groups.google.com/forum/#!topic/docker-user/thYVhVQ0Zfs
$ sudo docker commit -m="try angularjs docker" \
0b5f4a913336 \
3hdeng/angularjs-docker-try:angular-try-1

-->
error: No such container:

""" ...
You're trying to commit an image, not a container.
Do `docker ps -a` to see container
... """

*** image_id is different from container_id
image_id --> sudo docker images
container_id --> sudo docker ps -a



[remove container]
$ sudo docker rm container_id

[remove image]
$ sudo docker rmi username/repo_name:tag




//=== to install docker on Ubuntu Precise 12.04 (LTS) (64-bit)
*** to install docker on older release/kernel needs kernel update first
--> Linux kernel 3.8

""" ...
Due to a bug in LXC, Docker works best on the 3.8 kernel. Precise comes with a 3.2 kernel, so we need to upgrade it. ...

Please read the installation instructions for backported kernels at Ubuntu.org ...

# install the backported kernel
$ sudo apt-get update
$ sudo apt-get install linux-image-generic-lts-raring linux-headers-generic-lts-raring

# install the backported kernel and xorg if using Unity/Xorg
$ sudo apt-get install --install-recommends linux-generic-lts-raring xserver-xorg-lts-raring libgl1-mesa-glx-lts-raring

# reboot
$ sudo reboot

... """


2015年2月4日 星期三

github, add public key for ssh


//=== add public key to github

* gitbash on local computer
$ cd ~/.ssh
$ ls
config id_rsa id_rsa.pub known_hosts

$ cat id_rsa.pub > pub.txt
$ notepad pub.txt

* open browser
login into github.com website
--> click 'gear' icon on the top right menu
--> left side "SSH keys"

copy the contents of pub.txt
* not to wrap the line


github create repo via command line


//=== http://stackoverflow.com/questions/2423777/is-it-possible-to-create-a-remote-repo-on-github-from-the-cli-without-ssh

curl -u 'user13' https://api.github.com/user/repos -d '{"name":"phonecat1"}'
[https git]
git remote add github https://github.com/user13/phonecat1.git

[ssh git]
git remote add github git@github.com:user13/phonecat1.git

git push github master