Yuer Lee
    • 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
    --- slideOptions: spotlight: enabled: true --- Docker in Action 2e d - Ch1 Welcome to Docker === --- ## ToC 0. about this book 1. What is Docker? 1. “Hello, World” 2. Containers 3. Containers are not virtualization 4. Running software in containers for isolation 5. Shipping containers 2. What problems does Docker solve? 1. Getting organized 2. Improving portability 3. Protecting your computer ---- 3. Why is Docker important? 4. Where and when to use Docker 5. Docker in the larger ecosystem 6. Getting help with the Docker command line --- ## about this book 介紹 Docker、與 Linux container 觀念,分三部分: 1. Docker 與 container 特性,及使用他們的基本技能。 2. 透過 Docker 進行軟體包裝與散布(distribution)。 3. 探討 multi-container 專案與 multi-host 環境,包含 Docker Compose & Swarm,並以真實案例來建置與部署。 ---- **Resources** - [book website](https://www.manning.com/books/docker-in-action-second-edition) => 線上全文、電子版購買、討論 - [Docker hub repos](https://hub.docker.com/u/dockerinaction/) - [GitHub repos](https://github.com/dockerinaction) --- ## What is Docker - CLI 程式、background process。 - 軟體流通平台。 - 建立、執行、管理 container 的工具。 - 讓軟體包裝、散布、使用,能有低成本的最佳實踐。 - 比虛擬機器更快且更省資源。 - 讓使用者安裝、執行、移除程式都更容易。 --- ### Hello World (deprecated) ```bash # Install $ sudo apt install docker.io # Add user to docker group $ sudo usermod -aG docker {username} # Check $ docker version # Hello world! $ docker run dockerinaction/hello_world ``` **最新文件** - [Install on Ubuntu](https://docs.docker.com/engine/install/ubuntu/) - [Linux Postinstall](https://docs.docker.com/engine/install/linux-postinstall/) ---- **Running for the first time** ![](https://i.imgur.com/ojc3QSo.png) ---- **Running for the first time** ![](https://i.imgur.com/1fi9Tgr.png) ---- **Run again** ![](https://i.imgur.com/KRYaYFC.png) ---- **Run again** ![](https://i.imgur.com/OJGjH3h.png) --- ### Containers 一種 OS-level、孤立執行環境的,虛擬化技術。 >A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. https://www.docker.com/resources/what-container ---- **Naming** - `jail` => 1979 Unix-like OS,限制資源取用的執行環境。 - `container` => 2005 Solaris 10,以白名單模式限制程式取用資源。 - 有許多書中未提及的實作,如 1982 Unix-like OS 的 `chroot`,可參考 [wikipedia](https://en.wikipedia.org/wiki/OS-level_virtualization#Implementations)。 --- ### Containers are not virtualization - Virtual machine => 一個程式就要建立一台完整的虛擬機器,代表需要一個虛擬硬體,並耗費較多資源與時間來啟動 OS。 - Docker container => 不虛擬硬體,而是用 container 技術,並補足其不易設定之缺點。 - [wikipedia](https://en.wikipedia.org/wiki/OS-level_virtualization): Container is OS-level virtualization. ---- ### Running software in containers for isolation 直接執行程式 ![](https://i.imgur.com/PWINuUG.png) ---- 透過 Docker 執行 ![](https://i.imgur.com/M49C0PI.png) ---- Docker 使用 Linux 中 `namespaces` 跟 `cgroups` 來孤立每個 container。 ---- Docker 使用下列系統特性來建立 containers: - PID namespace - Process identifiers and capabilities - UTS namespace - Host and domain name - MNT namespace - Filesystem access and structure - IPC namespace - Process communication over shared memory - NET namespace - Network access and structure ---- Docker 使用下列系統特性來建立 containers: - USR namespace - User names and identifiers - chroot syscall - Controls the location of the filesystem root - cgroups - Resource protection - CAP drop - Operating system feature restrictions - Security modules - Mandatory access controls --- ### Shipping containers - 運送 container 的角色 => `image` ,其包含要執行程式所需檔案的 snapshot。 - Docker 提供了一些基本架構所需之元件(`registries` & `indexes`),幫助我們建構 `image`。 ---- >Images become containers when they run on Docker Engine. https://www.docker.com/resources/what-container --- ## What problems does Docker solve? --- ### Getting organized **不用 Docker** ![](https://i.imgur.com/sMzcWv4.png) ---- **不用 Docker** - 要在某個機器上,使用某套程式,其前置作業很痛苦 => 支援的 OS、安裝順序、調整設定、依賴軟體、依賴軟體的依賴軟體,還有他們的版本問題。 - 程式沒有隔離 => 版本不同、依賴不同、髒資料問題。 ---- **使用 Docker** ![](https://i.imgur.com/UZMgrbd.png) ---- **使用 Docker** - 優雅的使用,不用考慮管理問題。 - 各程式獨立運作,包含它們的依賴。 --- ### Improving portability - 軟體的依賴也包含了 OS 的不同。 - 更好的可攜性 => Docker as a runtime,比 JVM 更靈活,能執行各種語言的程式。 --- ### Protecting your computer 更安全 => 在 container 內執行程式,可控制其存取資源的權限。 ![](https://i.imgur.com/ojLKZgF.png) --- ### Why is Docker important? - 每個 Docker container 都可用一致的方式使用 - 就像貨櫃有各種品牌、裡面裝了各種貨物,但長寬大小皆一致,各種貨車、貨輪都可裝載。 ---- - 行成生態系,改變了系統管理、開發、部署的做法;省時間、省錢、省精力。 - 促進社群(包含 Amazon、Microsoft、Google)使用其與 Container 技術,進而讓它們更多選擇開源專案而非自建輪子。 ---- - 其特性使其成為跨平台系統的 App Store,其於原本的 Desktop 系統體系上所缺乏的。 - 讓大家更重視在 OS 上的孤立執行環境。 --- ### Where and when to use Docker - 使用上仍受制於 OS,Docker on Windows 無法執行 macOS app。 - 使用 Docker 執行程式讓電腦更安全且乾淨。 - 仍要注意資源存取權限的控制,以及小心來路不明的 `image`。 ---- **Docker Architecture** Docker uses a client-server architecture ![](https://i.imgur.com/lX0O4j8.png) ---- **Docker Architecture** - Docker Server - Daemon(`dockerd`) - listens for Docker API requests - manages Docker objects such as images, containers, networks, and volumes - can also communicate with other daemons to manage Docker services. ---- **Docker Architecture** - Docker Object - Images - a read-only template with instructions for creating a Docker container - an image is based on another image, with some additional customization - To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it ---- **Docker Architecture** - Docker Object - Containers - a runnable instance of an image - is relatively well isolated from other containers and its host machine ---- **Docker Architecture** - Client - users interact with Docker - `docker` command uses the Docker API - use commands such as `docker run`, the client sends these commands to `dockerd` ---- **Docker Architecture** - Registry - A Docker registry stores Docker images - Docker Hub is a public registry that anyone can use - You can even run your own private registry, ex: Harbor(企業等級) --- ### Docker in the larger ecosystem New or higher-leve problems: - container orchestration - high availability clustering - microservice life cycle management - visibility ---- - 許 Docker Plugin 或以 Docker 為核心的解決方案出現。 - Docker 也貢獻了部分如 runc、libcontainerd、notary。 ---- E.g. Kubernetes - Extensible platform for orchestrating services as containers in clustered environments. - Depends on container engines such as Docker. - Today building, customizing, or extending Kubernetes clusters is a full-time job. - This book focuses on and teaches solutions to higher-level problems using Docker alone. --- ### Getting help with the Docker command line - 善用 `docker` 指令。 - `$ docker help` - `$ docker help {COMMAND}` --- ## Q&A ---- 問題1: xxxxxxxx ---- 問題 2: xxxxxx

    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