Build costomize systems quickly

Setup is not easy......


It seems to one comman to complete
but errors always live on everywhere
Just a Application

Linux Container
aufs
Base Image

such as a root filesystem







Above Base Image










Dockfile
Configuring the Environment
Registry
a place of storing images

Implement
images & Containers
# 所有 image 清單
docker images
# 刪除 image
docker rmi <image id>
# 建立 ./Dockerfile 的 image
docker build .
# 建立 ./Dockerfile 的 image 但會刪除過程中的 container
docker build --rm .
# 不使用 cache 建立 image
docker build --no-cache .
# 結合以上兩行指令
docker build --rm --no-cache -t base .
# 建立完以後給他一個 tag asdc/base
docker build -t asdc/base .
# 匯出 / 匯入 image
docker export <CONTAINER ID> > <image name> / cat [tar file] | docker import - <image name>
# 保存 image
docker save <image name> / docker load <image name>
# 執行中的 container 的清單
docker ps
# 列出所有 container 的清單
docker ps -a
# 刪除 continer
docker rm <container id>
# 跑 base image,會產生一個 container
docker run base
# 跑 base image 並指定指令
docker run base /bin/ping www.google.com
# 用 daemon 模式跑
docker run -d base /bin/ping www.google.com
# (i)nterative (t)ty 跑 bash 就等於是進去他的 shell
docker run -i -t base /bin/bash
# 跑完以後自動把這個 container 砍掉,注意 --rm 和 -d 無法同時下
docker run --rm base /bin/ping www.google.com
# 把 Host 的目錄 mount 到 docker container 的目錄
docker run -v /host/folder:/docker/folder base
# attach 回某個 container, 如果跑的時候不是給 -d -i -t /bin/bash 的話是不能下指令的
# ctrl + c 會跳出。但如果是 -d -i -t /bin/bash ctrl + c 會 stop 整個 container.
# 在此情況下不想停止 container 只想跳出請用 ctrl + p, ctrl + q
docker attach <container id>
# 組合技,這樣可以用 docker attach 回去 shell
docker run -dit base /bin/bash

relation of all commands


Just like Github
build Dockerfile
# FROM: 指定 base image
FROM ubuntu:trusty
# MAINTAINER: 作者署名
MAINTAINER Feng Honglin <hfeng@tutum.co>
# RUN: 執行指令
RUN apt-get update && \
apt-get install -y nginx && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# ADD: 從本地端的目錄複製新的檔案到 container 的目錄
# format ADD <src> <dest>
# (和 COPY 雷同但 ADD 的<src>可以是URL)
ADD sites-enabled/ /etc/nginx/sites-enabled/
ADD app/ /app/
# EXPOSE: 指定listen的port
EXPOSE 80
# 指定Instance啟動後所要執行的指令
CMD ["/usr/sbin/nginx"]
# 常見的還有=>
# ENV: 環境變數設定
# WORKDIR: docker 執行的目錄
by tutumcloud/nginx
already support
AWS Elastic Beanstalk
Google Computer Engine
VMware
Microsoft
......
Driver for devops
deployment more fast and flexible
Benefit for TM
decrease costs and reduce developement time
Conclusion
Copy of Docker
By Yi Yang Chang
Copy of Docker
- 834