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 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
    # 六角鼠年鐵人賽 Week 4 - Docker Images 操作指令 ==大家好,我是 "為了拿到金角獎盃而努力著" 的文毅青年 - Kai== ### 秋夕 杜牧 :::info 銀燭秋光冷畫屏,輕羅小扇扑流螢。 天階夜色涼如水,坐看牽牛織女星。 ::: 前面簡單的介紹過 Docker Image 後,本篇文就會開始實際的操作各種 Image 的指令了。 ### 查詢映像檔資訊 #### 列出 Image 的基本資訊 ``` docker image ls docker image ls -a docker image ls --all docker images ``` ![](https://i.imgur.com/uNHSWAr.png) ![](https://i.imgur.com/yto70f3.png) :::success 上述四句指令功用完全一樣,因為程式預設會幫忙帶入 -a 或是 --all 的指令,因此不需要特別加,Docker 都會秀出所有 Image ::: #### 列出指定 Image 的基本資訊 ``` docker image ls [Image Name] docker images [Image Name] docker image ls [Image Name]:[TAG] docker images [Image Name]:[TAG] Kai 的操作範例為 docker image ls tomcat docker images tomcat docker image ls tomcat:7.0.100-jdk8-corretto docker images tomcat:7.0.100-jdk8-corretto ``` ![](https://i.imgur.com/a2KIyJl.png) ![](https://i.imgur.com/LSsZswo.png) :::success 如果只想列出某一支 Image 的話,可以在原先的指令後加入該 Image 的名稱 若想更加明確找出是哪一個版本,可以在後方 加上: 加上 TAG 輔助查詢 ::: #### 列出 Images 完整資訊(適用於指定 Image) ``` docker images --no-trunc docker image ls [Image Name] --no-trunc Kai 的操作範例 docker image ls tomcat --no-trunc ``` ![](https://i.imgur.com/rWrqUsX.png) ![](https://i.imgur.com/culFuFr.png) :::success 此指令會顯示完整 Images 的資訊 不論是全部 Images 還是單個 Image 都適用 ::: #### 查詢 Digests 值 ``` docker image ls --digests ``` ![](https://i.imgur.com/8huhHWh.png) :::success - Digests 是 Docker 1.6 和 registory 2 加入的資訊,是用來識別 Image 的 SHA值 - SHA值 是經由 SHA (全名Secure Hash Algorithm 安全散列函式) 算出的值,被廣泛使用在資安認證上 - SHA 同時也是 FIPS 所認證的安全雜湊演算法 - FIPS 全名 Federal Information Processing Standards 聯邦資訊處理標準 ::: #### 查詢透過 Filter 篩選 :::warning Filter 的寫法,可以是以下方式: ``` -f --filter ``` 後續接應的字串可以是 "Input String" 也可以接在 filter 後,等有需要輸入文字再輸入即可。 ``` -f 'dangling=true' -f=dangling='true' ``` ::: ``` docker images -f dangling=true docker images -f dangling=false ``` ![](https://i.imgur.com/x2zJvBi.png) :::success dangling 是表示那些沒有 TAG (標記)的 Image,常發生於自行建立的 Image 上,若是從 Docker Hub 或其他地方 pull 下來的幾乎都不會有這問題。 系統判定這些未被 TAG 的 Image,不被用於任何 Images Layer 中,同時也占用了磁碟空間,因此註記為 dangling,提醒開發人員此 Image 的狀況。 開發人員可以做的動作是將其 TAG、保持不變或刪除。 ::: ``` docker images -f "before=[ImageName:TAC]" docker images -f "since=[ImageName:TAC]" Kai 的操作範例 docker images -f "before=tomcat:7.0.100-jdk8-corretto" docker images -f "since=tomcat:7.0.100-jdk8-corretto" ``` ![](https://i.imgur.com/vB96QJy.png) ![](https://i.imgur.com/5e43eW4.png) :::success **before** 可以從範例中看出,是篩選列出某個 Image 往前(下)的其他 Image **since** 可以從範例中看出,是篩選列出某個 Image 往後(上)的其他 Image ::: ``` docker images -f=reference='Input String' Kai 的操作範例 docker images -f=reference='tomcat' ``` ![](https://i.imgur.com/li497V1.png) :::success 可以用來篩選出自同一個來源的 Images,像是 OS、DB、Apache 這類型的 Images 有可能會下載不只一個版本,眾多 Images 放在一起的時候難以整頓,這時候就可以利用 **reference** 來篩選同個來源的 Images,方便統整作業。 ::: :::warning 其他還有許多舉不完的例子,例如 **Label (label)**、**Running (running)** 等。 此外也支援 Linux 的查詢語法,所以也可以用類似 ``` docker images 'Input String\/*' docker images | grep Input String ``` 的方式來找尋 Images ::: #### 使用 format 進行 OutPut 控制 ``` docker images --format "{{.Item}}: {{.Item}}" Kai 的操作範例 docker images --format "{{.ID}} : {{.Tag}}" ``` ![](https://i.imgur.com/eUL03MJ.png) :::success 在 format 的 Item 中帶入正確的 Item Name 就可以指定該到資料欄位,下面是列出所有可以下的 Item Name: |Item Name|Info|Chinese Info| |-|-|-| |.ID|Image ID|Image 的 ID| |.Repository|Image repository|Image 倉庫名稱| |.Tag|Image tag|Image 的 TAG| |.Digest|Image digest|Image 的 digest| |.CreatedSince|Elapsed time since the image was created|Image 在 Local (本地端) 自建立到現在的時間| |.CreatedAt|Time when the image was created|Image 在 Local (本地端) 的建立時間| |.Size| Image disk size|Image 占用的空間| |.Name||Image 的名稱 (Search可用)| |.StarCount||Image 的星星積分 (Search可用)| |.IsOfficial||Image 是否為官方建立 (Search可用)| |.IsAutomated||Docker Hub 提供的功能,會在該 Image 的 Repo 更新時,自動根據 DockerFile 重建新 Image,目前適用 Github 和 Bitbucket (Search可用)| format 不限於在 Images 查詢時使用,包含下方的 Search 也可以下 format 指令 ::: ### Docker Hub Image 的操作 #### 查詢 Docker Hub 的 Image ``` docker search [Image Name] docker search --filter [filter condition] [Image Name] docker search --format "[format condition]" [Image Name] Kai 的操作範例 docker search mysql docker search --filter stars=10 mysql docker search --format "{{.Name}}: {{.StarCount}} : {{.IsOfficial}}: {{.IsAutomated}}" mysql ``` ![](https://i.imgur.com/QGBBwO1.png) ![](https://i.imgur.com/pQyM4OM.png) ![](https://i.imgur.com/i1e436k.png) :::success 透過此指令可以讓 Docker 連上 Docker Hub 找尋想找的 Image 另外還可以透過 Filter 方式篩選、Format 方式進行查詢結果輸出等功能 ::: #### 從 Docker Hub 下載 Image ``` docker pull [Image Name]:[TAG] docker pull [Image Name] -a docker pull [Image Name] Kai 的操作範例 docker pull mysql:5.7 ``` ![](https://i.imgur.com/cnv4iPD.png) :::success 透過 Pull 的方式,將想下載的 MYSQL 版本 Image,從 Docker Hub 抓下來 上述關於 docker pull [Image Name] -a docker pull [Image Name] 將會把所有的 Image 都載下來,會非常耗費時間與空間,請開發者確定要下載的 Image 後再單獨抓會比較好,當然若是有特殊需求需要全抓,那這兩句語法可以滿足你需要~ ::: ### Image 刪除 ``` docker rmi [Repository or Image ID] Kai 的操作範例 docker rmi hello-world ``` ![](https://i.imgur.com/yFRaXOm.png) :::success 可以用此指令刪除 Images,但要注意的是,若當 Image 正被 Container 使用的話,系統是不會給你刪除的,就算 Container 是 Stop 狀態也是一樣,可以使用 force 的方式刪除,但完全不建議這樣,會導致 Container 可寫層物件的毀損。 ::: ## 結語 :::danger 關於 Docker Image 的部分,其實還有很多部分沒有提到,但對於一般開發者來說,只要會上述基本款的就夠用了,其他透過官方文件的學習即可,就不放上來占版面了~ 下篇將會分享 **Build DockerFile** 的學習心得 [六角鼠年鐵人賽 Week 5 - Build a suitale Image by DockerFile](/FriZ-QVpQd6FC7OrzMsZzw) ::: 首頁 [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