Kai Chen
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 六角鼠年鐵人賽 Week 3 - 介紹 Docker 重要元素 ==大家好,我是 "為了拿到金角獎盃而努力著" 的文毅青年 - Kai== ### 夜泊牛渚懷古 李白 :::info 牛渚西江夜,青天無片雲。登舟望秋月,空憶謝將軍。 余亦能高詠,斯人不可聞。明朝掛帆去,楓葉落紛紛。 ::: Docker 是由 **Image (映像檔)**、**Container (容器)**、**Repository (倉庫)** 所組成。 ==或有人使用 Registory 代替 Repository,前者是指倉庫註冊服務器,專門存放多個 Repository== 其應用的流程如下圖 (擷取自網路): ![](https://1.bp.blogspot.com/-CBvM4xdqeVo/XHvu18li9bI/AAAAAAAAGH4/Ltbb4TMaRMwGTiCRaNmfZA65iSEkOa9dgCLcBGAs/s1600/dockercommand.png) ## Image 映像檔 Image 是一個唯讀的環境模板,可由 Dockerfile 建構,是以單個或多個 Image Layers 組成,用來建構容器實體且可重複執行,建構內容可包含 Container 內的函式庫、環境設定檔、軟體與程式。 就像建一棟房子要有的設計圖、做一個模型要先有模板那樣的存在。Image 就是給 Docker 在建構 Container 時候參照的依據。 目前在 Docker Hub 中已存在許多發布的 Image,也可以透過在 Docker cmd 中下指令搜索想要的 Image,可根據 Stars 星星點數去得知該 Image 的評比,越多點數代表越多人使用或推薦。 ==Docker Hub 是一個類似 GitHub 的網站,使用者可以透過註冊後,在其建構公開或私人的空間存放 Image,私人的空間需要付費申請== 若都沒有找到喜歡的 Image,則可以自己編寫 DockerFile 建構,在 DockerFile 中每一行建構出的 Image Layer 共同組成一個完整的 Image,從而建構出 Container。 當在 Docker cmd 去 pull 一個公開的 Image 時,常會看到許多的[hashcode]:pull,這就是在下載該 Image 的所有 Image layers,而一個 Image layer 又是由許多不同的小檔案組成,可以想像成 Git 作業中:一個小功能由許多的 commit 組成,一個模組又是由許多的功能組成,而許多模組最後可以做成一個產品。 而當同一個環境下載過的 Image layers 是可以給不同的 Image 共用的,因此也常會看見[hashcode]:Already exists的訊息。 ==下圖是一個正在下載 tomcat image 的範例圖,可以看到下載了許多 image layers== ![](https://i.imgur.com/12d6Tzo.png) 下列圖片取自 [Docker Doc](https://docs.docker.com/storage/storagedriver/#images-and-layers),可以更清楚瞭解其組成的結構。 ![image alt](https://docs.docker.com/storage/storagedriver/images/container-layers.jpg) Docker Image 不存在實際環境與程式的方式,使其檔案容量小,方便攜帶與分享,也就是這樣一種方式,讓 Docker 在建立環境上,不管是時間還是可靠性,都比 VM 來的更好。 ## Container 容器 若把 Image 比喻為 Java 的 Class,那 Container 就是透過 Class New 出來的實體。 容器是依據 Image 建構出的實體,且一個 Image 可重複建構相同的 Container,這些 Container 因 Namespaces 技術而得以獨立不受其他 Container 的干擾,就算他們是從同一個 Image 建構而來。 [詳細可參考 Wikipedia Linux Namespaces](https://en.wikipedia.org/wiki/Linux_namespaces) 容器是個獨立實體,可以進行啟動、停止與刪除,且當透過 Image 建立時,Container 會在其最上層加疊一層 Writable layer,又作可寫層或擴充層,讓 Container 保有延伸增減功用的彈性,而當 Container 移除時,該層也會一同被移除,但其基本的 Image 是不會被移除的,因此不必擔心 Local 端的 Image 或 Image layers 檔案不見,除非是手動刪除了。 ![image alt](https://docs.docker.com/storage/storagedriver/images/sharing-layers.jpg) ## Repository 倉庫 Repository 是集中存放 Images 的地方,而這些 Repository 則會建構於 Rigestory (倉庫註冊伺服器),因此有不少教學直接教 Rigestory 而不是 Repository。 目前來說開發者最常瀏覽的 Docker Hub,亦是目前公開 Images 數量最多的地方,且就像是 GitHub 一樣,不論是開發者 pull 自己想要的 Image 還是上傳自己建構的 Image,只需要註冊即可免費使用服務,開源的方式也讓更多便利的 Images 被建構提供出來,減少許多開發者建構 Images 的時間,把精力放在開發主要項目上。 ==目前 Docker Hub 提供一個帳號 一個免費 private Repository 的額度== ## 結語 :::danger 下篇將會分享操作 **Docker Images** 的學習心得 [六角鼠年鐵人賽 Week 4 - Docker Images 操作指令](/VXlsyHahSMOTT1CPLy_iyw) ::: 首頁 [Kai 個人技術 Hackmd](/2G-RoB0QTrKzkftH2uLueA) ###### tags: `Docker`,`w3HexSchool`

    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