秋分
    • 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 New
    • 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 Note Insights Versions and GitHub Sync 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: docker --- [TOC] # Chapter 3. Software installation simplified ![](https://i.imgur.com/knPU375.png) ## Identifying software ### named repository ![](https://i.imgur.com/cR6d4I6.png) #### `[REGISTRYHOST:PORT/][USERNAME/]NAME[:TAG]` :::info 一個 repository 裡面可能會有多個 image,可以用 tag 來做區別,若沒寫 tag 則預設使用 `latest` 這個 tag ::: ### using tags - tag 可以用來指向一個 repository 裡唯一的一個 image - 一個 image 可以有多個 tag ## finding and installing software :::info 當使用 `docker pull` 或 `docker run` 指令,卻沒指定 registry 時,會預設去 docker hub 找 ::: ### Working with Docker registries from the command line - Dockerfile - 一個 script 用來 build image - `docker login` 登入 registry - `docker login [OPTIONS] [SERVER]` - `--password` , `-p`密碼 - `--password-stdin`用 STDIN 的方式輸入密碼 - `--username` , `-u`使用者名稱 - `docker logout` 登出 registry - `docker logout [SERVER]` ### Using alternative > 簡單來說就是將你想去的 registry 位置寫上 - `docker rmi` 移除一或多個 image - `docker rmi [OPTIONS] IMAGE [IMAGE...]` - `--force` , `-f` 強置移除 - `--no-prune` 不移除 parent images ### Working with images as files - `docker load` 將一個 image 壓縮檔讀進來 - `docker load [OPTIONS]` - `--input` , `-i` 直接讀入壓縮檔,而非透過 STDIN - `--quiet` , `-q` 不顯示 load 訊息 ::: success - `$ docker load < busybox.tar.gz` - `$ docker load --input fedora.tar` ::: - `docker save` - `docker save [OPTIONS] IMAGE [IMAGE...]` - `--output` , `-o` 輸出成一個檔案,而非 STDOUT :::success - `$ docker save busybox > busybox.tar` - `$ docker save --output busybox.tar busybox` ::: ### Installing from a Dockerfile - `docker build` Build an image from a Dockerfile - `--tag` , `-t` 給予 image 跟與其 tag 名稱,tag 不一定需要,格式為 `name:tag` - option 太多,請看 [docker 官方文件](https://docs.docker.com/engine/reference/commandline/build) :::success `$ docker build .` `$ docker build -t dia_ch3/dockerfile:latest ch3_dockerfile` ::: - docker file 常會透過版控系統來發布 - `git clone https://github.com/dockerinaction/ch3_dockerfile.git` - `docker build -t dia_ch3/dockerfile:latest ch3_dockerfile` - docker file 缺點 - build 需要點時間 - dependencies may drift between the time when the Dockerfile was authored and when an image is built on a user’s computer ### Using Docker Hub from the website - 在 docker 你可以 - 搜尋 repository, 組織或特定使用者 - 在特定使用者或組織的頁面看到他們的 repository, 他們最近的活動或他們有按星星的 repository - 在 repository 頁面你可以看到 - 該 image 提供者寫的有關此 image 的資訊 - 可使用的 tags - 該 repository 創建時間 - 下載次數 - 其他使用者的留言 :::info #### docker hub 非唯一選擇,你也可以 - 使用其他 repository registries 或自己造一個 registry - 手動將 image 以檔案形式載入 - 從其他地方下載 project 然後用他提供的 dockerfile 自己 build ::: ## Installation files and isolation :::info 多數時候我們說的 image 其實指的是 image layers 的集合 layer 指的又是一個 file & file metadata 的集合,是個不可分割的最小單位 在 docker 內部,layer 會被看做一個 image,layer 也會被叫做 intermediate(中間的) images ::: ### image layers in action - `docker pull dockerinaction/ch3_myapp` - `docker pull dockerinaction/ch3_myotherapp` :::success 你應該會發現裝第二個會比裝第一個快(除非你網路太快或已經裝了那兩個 image 的 dependencies), 這是因為在裝第一個 image 時他會發現需要先安裝 `openjdk:11.0.4-jdk-slim` 因為那是他的 direct dependency(parent layer), 當把所有 dependencies 都裝完之後,最小的 layer 才會開始安裝, 而第一個 image 已經把第二個 image 的 dependencies 都裝完了,所以便可以直接開始安裝第二個 image。 ::: - `docker images` 會看到剛剛裝的兩個 image - `docker images -a` 會看到所有 layers :::info 若要將剛剛裝的幾個 image 清除 ``` docker rmi \ dockerinaction/ch3_myapp \ dockerinaction/ch3_myotherapp ``` ::: ### Layer relationships :::info images 可以和其他 images 有 parent/child relationships,就算是不同 repository 不同擁有者。 例如剛剛的兩個 image,`OpenJDK 11.0.4` 是他們的 parent image,下圖描繪了他們之間的關係。 ![](https://i.imgur.com/kskBgLN.png) - scratch: 最一開始的 base image,裡面甚麼東西都沒有 ::: ### Container filesystem abstraction and isolation - union filesystem (UFS) - 讓軟體不會認為自己是在一個 layer,而是一個完整的軟體架構裡 ### Benefits of this toolset and filesystem structure :::success #### 此功能的優點 - 相同的 layer 只需要被安裝一次,就算安裝了多個 image 而他們都有同樣依賴的 layer 那也不需重覆安裝 - 透過觀察 images 跟 layers,可快速知道現在有什麼軟體正在執行 ::: ### Weaknesses of union filesystems <!-- ## 問題 - 不太確定 3.3 倒數第六行的," Most layers build upon a parent layer by applying filesystem changes to the parent" 是什麼意思 - 3.3.3 what is MTN - 3.3.3 幾乎看不懂啊 - 3.3.4 第三段不是很懂 - 3.3.5 也看不是很懂 -->

    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