cy
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 容器化技術 `介紹容器化技術與版本控制` ###### tags: `RD1` :::spoiler 目錄 [TOC] ::: ## 虛擬化是什麼 ![](https://i.imgur.com/TfTRbkj.png) 這句話你去問不同背景的人可能會有不同的答案。 問編譯器背景的人他們可能會說JVM(Java virtual machine)、LLVM(Low level virtual machine)、V8 Engine..... 問作業系統背景的人他們可能會說是一種在作業系統模擬出硬體環境運行另一套作業系統的技術,像是VM ware、Virtual Box、Hypervisor..... 問網頁開發背景的人他們可能會說容器化技術,像是Docker、LXC(Linux Containers)..... 所以,說了這麼多虛擬化到底是什麼? **虛擬化技術就是一種模擬出虛擬環境供目標實體(程式語言、作業系統、應用程式)運行的技術。 目的就是為了解決不同環境下也可以運行目標實體。** ## Docker介紹 > 此段文章引用自[Docker 基礎教學與介紹 101](https://medium.com/unorthodox-paranoid/docker-tutorial-101-c3808b899ac6) Docker是一種幫你管理容器的工具,他可以將應用程式所需的環境打包,建立資源管控機制隔離各個容器,分配容器有效使用實體機器上作業系統的資源。透過容器,應用程式不需要再另外安裝作業系統(Guest OS)也可以執行。 ## 為什麼我們需要Docker > 此段文章引用自[《Docker —— 從入門到實踐》正體中文版 ](https://philipzheng.gitbook.io/docker_practice/introduction/why#geng-jian-chan-de-guan-li) #### 更快速的交付和部署 對開發和維運(DevOps)人員來說,最希望的就是一次建立或設定,可以在任意地方正常執行。 開發者可以使用一個標準的映像檔來建立一套開發容器,開發完成之後,維運人員可以直接使用這個容器來部署程式碼。 Docker 可以快速建立容器,快速迭代應用程式,並讓整個過程全程可見,使團隊中的其他成員更容易理解應用程式是如何建立和工作的。 Docker 容器很輕很快!容器的啟動時間是秒級的,大量地節約開發、測試、部署的時間。 #### 更有效率的虛擬化 Docker 容器的執行不需要額外的虛擬化支援,它是核心層級的虛擬化,因此可以實作更高的效能和效率。 #### 更輕鬆的遷移和擴展 Docker 容器幾乎可以在任意的平台上執行,包括實體機器、虛擬機、公有雲、私有雲、個人電腦、伺服器等。 這種兼容性可以讓使用者把一個應用程式從一個平台直接遷移到另外一個。 #### 更簡單的管理 使用 Docker,只需要小小的修改,就可以替代以往大量的更新工作。所有的修改都以增量的方式被分發和更新,從而實作自動化並且有效率的管理。 #### 對比傳統虛擬機總結 | 特性 | 容器 | 虛擬機 | | -------- | -------- | -------- | | 啟動 | 秒級 | 分鐘級 | |硬碟容量|一般為 MB|一般為 GB| |效能|接近原生|比較慢| |系統支援量|單機支援上千個容器|一般幾十個| ## Docker三元素 > 此段文章引用自[Docker 基礎教學與介紹 101](https://medium.com/unorthodox-paranoid/docker-tutorial-101-c3808b899ac6) #### 映像檔 Image Docker 映像檔是一個模板,紀錄容器的設定,用來重複產生容器實體。例如:一個映像檔裡可以包含一個完整的 MySQL 服務、一個 Golang 的編譯環境、或是一個 Ubuntu 作業系統。透過 Docker 映像檔,我們可以快速的產生可以執行應用程式的容器。而 Docker 映像檔可以透過撰寫由命令行構成的 Dockerfile 輕鬆建立,或甚至可以從公開的地方下載已經做好的映像檔來使用,也可以由當前的容器製作。 #### 容器 Container 就像是用蛋糕模具烤出來的蛋糕本體,容器是用映像檔建立出來的執行實例。它可以被啟動、開始、停止、刪除。每個容器都是相互隔離、保證安全的平台。可以把容器看做是一個執行的應用程式加上執行它的簡易版 Linux 環境(包括 root 使用者權限、程式空間、使用者空間和網路空間等)另外要注意的是,Docker 映像檔是唯讀(read-only)的,而容器在啟動的時候會建立一層可以被修改的可寫層作為最上層,讓容器的功能可以再擴充。 #### 倉庫 Repository 倉庫(Repository)是集中存放映像檔檔案的場所,也可以想像成存放蛋糕模具的大本營。倉庫註冊伺服器(Registry)上則存放著多個倉庫。最大的公開倉庫註冊伺服器是上面提到過的 Docker Hub,存放了數量龐大的映像檔供使用者下載,我們可以輕鬆在上面找到各式各樣現成實用的映像檔。而 Docker 倉庫註冊伺服器的概念就跟 Github 類似,你可以在上面建立多個倉庫,然後透過 push、pull 的方式上傳、存取。 ## Docker映象(Image)堆疊 ![](https://i.imgur.com/CG0DkEc.png) 由於Docker的映象只能讀不能寫,所以在擴充套件的時候必須先將映象運行成容器,在運行成容器後在安裝需要的函式庫或套件;之後再將此容器製作成映象。之後這個映象要擴充功能就照著上述步驟再做一次。這樣的動作就叫映象堆疊,Build Dockerfile就是這樣製作映象的。 > 記住映象檔堆疊不能超過127層 ## Docker的工作流程 ![](https://i.imgur.com/dSICh2n.png) ## Docker的入門實作 1. 使用Docker架設簡易apache伺服器 ``` git clone https://github.com/TerryHuangchungyo/docker_practice.git 觀看tutorial1.txt照著步驟執行 ``` 2. 使用Docker架設簡易多容器lamp環境 ![](https://i.imgur.com/wZssZ5D.png) ``` git clone https://github.com/TerryHuangchungyo/docker_practice.git 觀看tutorial2.txt照著步驟執行 ``` ## Docker Compose介紹 ![](https://i.imgur.com/zHdxP9c.png) > 此段文章引用自[菜鳥教程Docker Compose](https://www.runoob.com/docker/docker-compose.html) Compose 是用於定義和運行多容器 Docker 應用程序的工具。通過 Compose,您可以使用 YML 文件來配置應用程序需要的所有服務。然後,使用一個命令,就可以從 YML 文件配置中創建並啟動所有服務。 Docker Compose 使用的三個步驟: > 此段文章引用自[利用 Docker Compose 管理多個容器](https://www.coderbridge.com/@Jemmy1234/6d48f03f39284fe98ae9808f1243ef98) 1. 使用 Dockerfile 定義應用程序的環境。 2. 使用 docker-compose.yml 定義構成應用程序的服務,這樣它們可以在隔離環境中一起運行。 3. 最後,執行 docker-compose up 命令來啟動並運行整個應用程序。 為什麼需要Docker Compose? * 想要利用一份檔案管理多個 docker container 時。 * 希望多個 docker container 彼此之間有所關聯時 (docker compose 會為當前專案創建一個內部網路,service間可以互連)。 * 希望建立類似 CI workflows,可以用來開發、測試、與建立 staging 環境。 ## Docker Compose的入門實作 1. 使用Docker Compose架設簡易多容器lamp環境 ``` git clone https://github.com/TerryHuangchungyo/docker_practice.git 觀看tutorial3.txt照著步驟執行 ``` 2. 使用laradock架設laravel所需環境,並運行laravel ``` git clone https://github.com/TerryHuangchungyo/docker_practice.git 觀看tutorial4.txt照著步驟執行 ``` ## 參考資料 [1] Docker 基礎教學與介紹 101 https://medium.com/unorthodox-paranoid/docker-tutorial-101-c3808b899ac6 [2] 《Docker —— 從入門到實踐》正體中文版 https://philipzheng.gitbook.io/docker_practice/ [3] 使用docker-compose構造LAMP環境 https://www.itread01.com/xxell.html [4] Docker Compose 建置 Web service 起步走入門教學 https://blog.techbridge.cc/2018/09/07/docker-compose-tutorial-intro/ [5] 利用 Docker Compose 管理多個容器 https://www.coderbridge.com/@Jemmy1234/6d48f03f39284fe98ae9808f1243ef98 [6] 菜鳥教程Docker Compose https://www.runoob.com/docker/docker-compose.html

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully