Docker 基礎入門概要信息

    這裏主要是通過對官網幾篇入門文字的梳理,摘要,擬出重要概念,讓埋頭進去學的時候,有個主脈絡,可以先理解一些概要理解;

 

爲什麼用docker:

    1. 輕量- 相比較 虛擬機 ,docker 不會再模擬一套OS出來,然後運行我們的應用在上面;

    2. 便利性 - 本地編譯,雲端部署(發佈到 中央庫),任何地方運行(只需要一個docker 命令,整套你的app依賴的都完整的搬過來運行)。

    3.擴展性 - docker本身支持,集羣部署控制,或者是docker實例的複製(你可以看做是配置文件控制一個應用按照N個進程來運行 )

    4. 可層疊 - 一套業務,依賴N個service, 那麼可以N個service整體打包爲一個,讓整個垂直業務依賴的服務都就緒;

 

安裝:

     一般情況,日常學習就MAC上安裝個 Docker Desktop ,裏面包含了Docker引擎 , 客戶端(命令行),Docker Compose, Docker Machine 和 Kitematic

    (Linux 如 centos, ubuntu 等 安裝的時候可以通過配置 repo 然後跟隨命令行 進行安裝 )

 

使用:

    重點 !!!! 做看幫助文檔, docker --help 啥都在裏面了!!!! 

     以下內容討論都是基於 官方網站的docker get started 爲基礎。請參看:https://docs.docker.com/get-started/

    請跟隨講解邊看邊做。 動手是最重要的部分~_~|||  ~_~|||  ~_~ |||

 

    坑1: docker run hello-world 

            這個命令,如何你沒有 docker login 過,你是運行不了的, 兩個要點 1. 第一次運行你本地沒有hello-world 的鏡像 (所以需要走docker 的 雲端 public 庫拉取) 2 拉取需要你有docker id ,你需要去官網註冊,用 docker login 命令 賬號密碼登錄後再運行,一般就OK 了。

 

    經驗,如下 dockerfile的使用。

# Use an official Python runtime as a parent image
FROM python:2.7-slim # Set the working directory to /app
WORKDIR /app # Copy the current directory contents into the container at /app
COPY . /app# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80# Define environment variable
ENV NAME World# Run app.py when the container launches
CMD ["python", "app.py"]

        思考下docker的容器怎麼能解決我再windows上部署linux container 呢,如果不能解決,我還是必須要去找一個linux真機或虛擬機才能運行linux的程序,就談不上方便了。

        其實就是通過 FROM 語句,在from 語句中可以引入parent image 鏡像是個centos 或 ubuntu的 系統,作爲paraent image .從而解決跨平臺,即在MAC 或windows上運行 linux 的問題。

 

    坑2: 構建鏡像 docker build --tag=friendlyhello .

        注意別丟了最後的那個 點號 。

 

    坑3:docker run -p 4000:80 friendlyhello 

            這個命令實際運行的時候,在MAC上發現,如果本地host端口配的過大,會導致命令失敗,建議一般就控制在4位數就合適了。4000~9999 都比較合適。

 

 

關鍵名詞解釋:

    ​Docker Image:

    ​    ​鏡像文件,類似是 docker container 的模板,通過它創建 docker 容器;

 

    ​Docker Container:

    ​    ​獨立運行的一個或者一組應用(按照鏡像要求或者說配置,創建出來的對象)

 

    ​Docker Registry:

    ​    ​Docker 倉庫,用來保存鏡像文件,等同於GITHUB 作爲代碼庫的概念; 公共的倉庫是 Docker Hub(https://hub.docker.com 註冊賬號)    ​

 

    Dockerfile 

    類似於cmake的CMakeList.txt 文件,用Docker定義的一套指令,定義如何侯建一個container(一般來講裏面會制定依賴,具體依賴的版本號等)

 

    Docker Toolbox

    Docker Compose

        Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

 

    Docker Machine 

        Docker Machine is a tool that lets you install Docker Engine on virtual hosts, and manage the hosts with docker-machine commands. You can use Machine to create Docker hosts on your local Mac or Windows box, on your company network, in your data center, or on cloud providers like Azure, AWS, or DigitalOcean.

 

    Kitematic

        Kitematic is an open source project built to simplify and streamline using Docker on a Mac or Windows PC. Kitematic automates the Docker installation and setup process and provides an intuitive graphical user interface (GUI) for running Docker containers. Kitematic integrates with Docker Machine to provision a VirtualBox VM and install the Docker Engine locally on your machine.

 

    Service:

    In a distributed application, different pieces of the app are called “services”. For example, if you imagine a video sharing site, it probably includes a service for storing application data in a database, a service for video transcoding in the background after a user uploads something, a service for the front-end, and so on. (一個程序實例算一個service)

 

    ​Swarm clusters:

    A swarm is a group of machines that are running Docker and joined into a cluster. After that has happened, you continue to run the Docker commands you’re used to, but now they are executed on a cluster by a swarm manager. The machines in a swarm can be physical or virtual. After joining a swarm, they are referred to as nodes.

    ​(Swarm 集羣可以想象成,爲了多機器部署和管控,引出來的方法,1個或多個(少量的manager機器)管控 N 個worker 機器。 在控制機器上的操作會轉發的 worker 機器上。 )

 

    ​Stack:

    ​A stack is a group of interrelated services that share dependencies, and can be orchestrated and scaled together.

 

    ​這裏 Clusters 和 Stack 構成了橫向擴容和縱向闊服務深度(多種服務同時具備到一個鏡像)的一種能力;

 

其它一些參考內容:

    Docker中文網:http://www.docker.org.cn/index.html

    菜鳥網的 docker介紹,https://www.runoob.com/docker/docker-command-manual.html 非常利於理解基本必要的概念。

   Docker使用了k8s ,它中文 http://docs.kubernetes.org.cn 主頁。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章