tienyulin
    • 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Docker (一) - 容器與 Docker 的基本概念 ![Docker](https://i.imgur.com/Gyd2FU1.jpg) Docker 是一個容器化的軟體平台,可以快速的建立、測試和部署應用程式。透過 Docker 將應用程式的程式碼及執行時所需的項目打包,可以讓應用程式在不同環境上快速的運行。 然而 Docker 只是一個容器化的工具,要了解 Docker 首先要先了解什麼是容器、什麼是虛擬化。 <!--more--> ## 虛擬化 虛擬化(Virtualization)是一種資源管理的技術,他可以將電腦的各種實體資源抽象化後再進行分配,例如: 記憶體、硬碟、網路等等。 而虛擬化的目的是為了模擬出一個環境,讓應用程式可以再不同電腦但是相同的環境上執行,以避免換了環境,程式就無法正常運作的問題。 常見的虛擬化技術有兩種,第一種是虛擬機(Virtual Machine),第二種是容器(Container)。 ## 虛擬機(Virtual Machine)與容器(Container)的差異 ### 虛擬機 虛擬機是用硬體端的 Hypervisor 技術來同時執行多個虛擬主機,Hypervisor 可以在現有作業系統(Host OS)上再安裝作業系統(Guest OS)。 使用虛擬機的好處是: * 每個應用程式擁有獨立的作業系統和環境 * 每個虛擬機的資源(CPU、RAM)獨立擁有 但是使用虛擬機也有一個非常大的缺點,虛擬機會佔用非常大量的運行資源,因而衍生出了容器。 ![VM](https://www.inwinstack.com/wp-content/uploads/2017/10/%E9%9B%BB%E5%AD%90%E5%A0%B11.png) ### 容器 容器是在作業系統上虛擬化應用程式,將應用程式所需的程式碼、函式庫和執行環境打包,並且分配 Host OS 上的系統資源。所以相對於虛擬機,容器不會額外安裝運行作業系統(Guest OS),應用程式便可以直接執行。 使用容器的的優點不勝枚舉,例如: * 虛擬機的映像檔通常大小至少數 GB,而容器的映像檔一般最大也只有數百 MB,在管理、啟動及關閉都快很多 * 只要伺服器上安裝了 Docker 或是其他容器化的軟體平台,不論 Host OS 是甚麼都可以正常運行容器化後的應用程式 * 容器有不可變的特性,只要應用程式能正常執行一次,也就不會因為系統環境變動而產生問題 然而容器也因為不可變,所以如果未來需要修改或升級系統環境就可能產生問題;但是還是可以透過重新建立容器的方式來修改環境,重新建立容器再部署到伺服器上的速度仍然會比使用虛擬機器來的快。 不過若是很常需要更動到系統環境的話,還是比較建議使用虛擬機,虛擬機可以較輕易的管理系統環境。 ![Container](https://www.inwinstack.com/wp-content/uploads/2017/10/%E9%9B%BB%E5%AD%90%E5%A0%B12.png) ## Docker的核心概念 ### 映像檔 Image 映像檔是一個模板,包含了所有執行所需要的程式碼、函式庫及執行環境等,他可以用來重複產生容器的實體。一個映像檔可以包含像是一個 SqlServer、一個 Windows 作業系統或是一個 DotNet 的應用程式。 映像檔本身是唯讀且不可更改的,這樣才能確保在不同雲端平台,都有相同的系統環境。 我們可以透過自己撰寫 Dockerfile 來定義建立映像檔時需要做的事情,而 Dockerfile 是由許多命令所組成的 `YAML` 文字檔。 ### 容器 Container 容器是利用映像檔所創造的實例(instance),透過一個映像檔可以創造出多個不同的容器,每個容器都是獨立運作相互不干擾的。 呈上述所說,映像檔是唯讀的,而容器會在啟動時加上一層可寫層在最上層,讓容器還可以再擴充。每個容器的可寫層也是獨立的,不用擔心會影響到映像檔建立下一個容器,無論容器可寫層做了甚麼修改,同樣的映像檔建立出來的容器都會是一樣的。 ### 倉庫 Repository 倉庫是用來存放映像檔的地方,而倉庫註冊伺服器(Registry)則存放了很多的倉庫。 Docker 提供了最大的倉庫註冊伺服器 [DockerHub](https://hub.docker.com),內部存放了非常大量的公開映像檔給開發者們下載使用,例如: ubuntu、python、sqlServer, etc. DockerHub 可以透過 push 將映像檔上傳,再用 pull 將映像檔下載下來。 ## 參考 [1] [Docker-介紹 | iT邦幫忙](https://ithelp.ithome.com.tw/articles/10209078) [2] [淺談輕量化的虛擬技術 - Docker容器](http://www.cc.ntu.edu.tw/chinese/epaper/0036/20160321_3611.html) [3] [10個Q&A快速認識Docker | iThome](https://www.ithome.com.tw/news/91847) [4] [Docker官方網站](https://www.docker.com/) [5] [容器化 .NET Core 應用程式(建立image、建立container)](https://docs.microsoft.com/zh-tw/dotnet/core/docker/build-container) [6] [將 ASP.NET Core 部署至 Docker 中](https://blog.yowko.com/aspnet-core-docker/) [7] [什麼是 CICD | iT邦幫忙](https://ithelp.ithome.com.tw/articles/10219083) [8] [針對 .NET 容器要設為目標的作業系統](https://docs.microsoft.com/zh-tw/dotnet/architecture/microservices/net-core-net-framework-containers/net-container-os-targets) [9] [How Visual Studio builds containerized apps](https://docs.microsoft.com/en-us/visualstudio/containers/container-build?view=vs-2019) [10] [Connecting to local or remote SQL Server from Docker Container](https://vivekcek.wordpress.com/2018/06/10/connecting-to-local-or-remote-sql-server-from-docker-container/) [11] [如何取得Container ip](https://blog.yowko.com/container-ip/) [12] [簡單部署 Docker Swarm 測試叢集](https://k2r2bai.com/2016/11/16/container/docker-swarm/) ###### tags: `Container` `Docker`

    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
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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