2017年1月19日 星期四

docker command line summary

docker command line summary
===========================

image: a read-only file system consisting of a base layer and a series of difference layers
container: a writable file system consisting of an image and a top writable layer with network and volume hooks

an image has id, name, tag, read-only_layers, entrypoint, and cmd
a container has id, name, source_image, writable_layer, overwrite_cmd,
  cpu_limit, memory_limit, volume_hook, network_hook, and state (active/un-active)

what docker can do with images in a local image store
  -- creation --
  - import/export with docker hub
   search in a docker hub (docker search)
   pull from a docker hub (docker pull)
   push to a docker hub (docker push)
  - import/export with local filesystem
   load from a local file (docker load)
   save to a local file (docker save)
  - born from scratch
   commit an un-active container to create an image (docker commit)
   build an image with Dockerfile instructions (docker build)
 
  -- management --
  list (docker images)
  remove (docker rmi)

what docker can do with containers in a local container store
  -- creation -- 
   create an un-active container from an image (docker create)
   run from an image with an overwrite command (docker run)
   execute a command (docker exec)

  -- management
   stop an active container with a grace period (docker stop)
   kill an active container (docker kill)
   start an un-active container (docker start)
   restart an active container (docker restart = docker stop + docker start)
  -
   copy with local filesystem (docker cp)
  -
   attach the console to a container (docker attach)
  -
   commit an un-active container to create an image (docker commit)
  -
   list (docker ps [-a])
   remove (docker rm [-f])

an image runs a new container with an overwrite command
= an image creates a new container + the container starts with an overwrite command

a container is created when docker creates from an image or runs from an image with an overwrite command
an image is created when docker commits a container or builds from a base image and a Dockerfile

#
#
# image operation
#
#

#### search for an image
docker search image_keyword

#### download an image
docker pull [registry.hub.docker.com/]image_path[:tag] 

#### list images in local drive
docker images [image_path]

#### create new images
1.docker commit -m "submit message" -a "submit user" container_id image_path[:tag]

 $ vi ./Dockerfile
 # This is a comment
 FROM ubuntu:14.04
 MAINTAINER Docker Newbee <newbee docker.com="">
 RUN apt-get -qq update
 RUN apt-get -qqy install ruby ruby-dev
 RUN gem install sinatra
 # put my local web site in myApp folder to /var/www
 ADD myApp /var/www
 # expose httpd port
 EXPOSE 80
 # the command to run
 CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]

2.docker build -t="image_path:tag" .  

3.cat ubuntu-14.04-x86_64-minimal.tar.gz  | docker import - ubuntu:14.04

4.docker tag container_id image_path:new_tag

#### upload an image
docker push image_path # all tags

#### save and load an image as local file 
docker save -o ubuntu_14.04.tar ubuntu:14.04

docker load --input ubuntu_14.04.tar
docker load < ubuntu_14.04.tar

#### remove a local image
docker rmi image_path

#
#
# container operation
#
#

#### start and run a container with an image
docker run [-name container_name] ubuntu:14.04 /bin/echo 'Hello world'
docker run -t -i ubuntu:14.04 /bin/bash   ### start a container in interactive mode
docker start ubuntu:14.04

docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
docker ps [-a]     ### list containers, [all, inclusive of un-active containers]
docker logs insane_babbage

#### start and stop container
docker restart
docker stop
docker run -idt ubuntu
docker attach container_name

#### start a shell in a container, detach from it, and re-attach to it
docker exec -it container_name /bin/bash
# use Ctrl-p + Ctrl-q to detach from the container
docker attach container_name

#### import and export container 
docker export container_id > snapshot.tar
cat snapshot.tar | docker import - image_path[:tag]
docker import snapshot_url image_path

#### remove container
docker rm container_name
docker rm $(docker ps -aq)  ## remove all exited containers



References:
1.《Docker —— 從入門到實踐­》Run命令
2.How to use Docker without sudo on Ubuntu
  # grant docker permission to specific user 'foobar'
  > sudo setfacl -m user:foobar:rw /var/run/docker.sock
  > getfacl /var/run/docker.sock
  getfacl: 從絕對路徑名尾部去除“/”字符
  # file: var/run/docker.sock
  # owner: root
  # group: docker
  user::rw-
  user:foobar:rw-
  group::rw-
  mask::rw-
  other::---
3.Play With Docker provides an Alpine Linux 3.10 environment with docker and git ready for use
     CPU: Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz with 8 cores
     Memory: 32GB
     Drive: 64GB with 16GB used
     Limit: Use of up to 5 nodes for up to 4 hours per session

2017年1月15日 星期日

integer and float division in C

>celsius = (5 / 9) * (fahren - 32);
>不管打什麼fahren數字,celsius都是 0
>我把 5 或 9 換成 5.0 或 9.0, 再compile和execute就正常。

C或Java高階語言重視數字型別,將除法運算(/ operator)分成整數除法及實數除法。
整數除法的商結果為整數,小數忽略。
實數除法的商結果為實數。
決定整數或實數除法是由運算子(operand)型別決定:
(1)  整數 / 整數 = 整數商
(2)  實數 / 實數 = 實數商
(3)  整數 / 實數 = ?數商
(4)  實數 / 整數 = ?數商

例子 5/9 屬於情況(1)所以得到結果為0;
至於 5.0 / 9.0 屬於情況(2)所以得到結果有小數。
至於情況(3)及(4)結果為何,可以實驗一下。
(情况 3 跟 4 结果會以最精確的型別為準,輸出實數商)

除了加.0將整數變實數,也可以利用轉型運算子,寫法如下:

  celsius = ((float) 5 / (float) 9) * (fahren - 32);

數字前面加 (float) 運算子可將其型別轉為float。

2017年1月12日 星期四

C pointer concept in Java

>關於C語言裡指標變數的概念,指標變數和一般變數的差別在哪? Java語言中是否沒有這類概念?

C語言中只要宣告時加*號就是指標變數,例如: int *p; 的p就是指標變數。變數p存的是某整數空間的住址,透過p可以存取該整數 空間的整數。

Java沒有明確的指標觀念,但是所有宣告為參考型別的變數都可隱含視為類似指標的變數。例如: Integer n;的n就是整數物件變 數。變數n存的是某整數物件編號,透過n可以存取該整數物件的整數。

the cold start problem in user-based collaborative filtering

>如果使用user-based的協同過濾來進行產品推薦,對於新加入的使用者,他還沒有對任何產品的評分紀錄,因此似乎沒有辦法找出與其相近的鄰居,此時是否需要混用其他方式進行推薦呢?

協同過濾推薦技術遇到新用戶無法推薦的情況稱為冷啟動問題。一般常混用基於內容推薦或知識推薦技術作輔助。另外新用戶也可使用非個人化推薦作法,就其目前感興趣項目進行短暫(ephemeral)推薦。有關解決協同冷啟動的問題,可參考如下電子書第1章之多處討論。

aggarwal-16- springer-recommender systems- the textbook