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

    Note:
  • 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])
    Note:
  • 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.Prepare docker.service.d/override.conf for the systemd drop-in service
  > sudo systemctl edit docker
  [Service]
  ExecStartPost=/bin/sh -c '/usr/bin/setfacl -m user:foobar:rw /var/run/docker.sock'
  > sudo systemctl daemon-reexec	# re-execute the systemd process
  > sudo systemctl daemon-reload	# reload the systemd manager configuration
  > sudo systemctl restart docker	# stop and start the docker service
    
4.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

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。

C Pointer Concepts in Java

學過 C 語言,轉換到 Java 語言時,常有如下困擾。 相較於 C 語言的變數分成 指標變數 (pointer variable) 和 非指標變數 (non-pointer variable),兩者可由型別前面是否有加 * 號作區隔。那麼, Java 語言沒有加 * 號的指標變數,若遇到須要指標的情境,例如鏈結清單 (linked list) 或 圖形結構(graph),該如何應對?

答案是 Java 語言有所謂參照變數 (reference variable) 的設計,以對應於 C 語言的指標變數。以下將舉例說明。

C 語言中只要變數宣告時,型別前面加 * 號就是指標變數,例如:


     int i = 3; // 宣告整數變數 i,記憶體切一塊整數空間,裏頭填入整數 3
     int *p; // 宣告整數指標變數 p,記憶體切一塊指標空間,裏頭值未定
     p = &i; // 將變數 i 住址填入變數 p 指標空間

其中,i 是一般 整數型別 (int) 變數,變數 i 存放的是記憶體空間中,某位址的整數,透過 i 可以存取該整數。 p 前面加 *, p 就變成 整數指標型別 (int *) 變數,變數 p 存放的是記憶體空間中,某塊可存放整數的住址,透過 p 可以存取該住址的整數。在第3行指令,p 接收 i 住址之後,兩者產生連動,*p 和 i 將看到相同內容,整數 3。

Java 語言則沒有明確的指標觀念,所有變數只分成基本型別 (primitive type) 及非基本型別 (non-primitive type)。基本型別限定8種,包含 boolean, char, byte, short, int, long, float, double。基本型別的保留字開頭皆小寫,用途和 C 語言類似,其變數可直接存取該變數值。

非基本型別又稱 參照型別 (reference type),包含所有 類別,介面,陣列,列舉等參照型別。參照型別的變數存放的是參照值,可想像成記憶體位置值,或物件索引值。例如:


     // 宣告整數參照變數 r,記憶體切一塊參照空間,裏頭填入 null
     Integer r; 
     
     // 建立存放整數 4 的整數物件,將其索引值填入變數 r 的參照空間
     r = new Integer(4);

其中, r 就是整數參照變數。變數 r 存放某整數物件的索引值之後,透過 r 可以存取該整數物件的整數 4。

the cold start problem in user-based collaborative filtering

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

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

aggarwal-16- springer-recommender systems- the textbook

Building a Lightweight Streamlit Client for Local Ollama LLM Interaction

Ollama 提供端點串接服務,可由程式管理及使用本地大語言模型(LLM, Large Language Model)。 以下程式碼展示如何以 Streamlit 套件,建立一個輕量級的網頁介面,供呼叫 本地端安裝的 Ollama 大語言模型。 Ollama 預設的服務...

總網頁瀏覽量