張揚翔
    • 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
    2
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 不賴陪你玩 Docker docker 自架服務不求人 - 發問與投票連結:sli.do #docker https://hackmd.io/@fly/docker101 --- ## 嘿!兩兩分組認識一下如何? (15 mins) - 分組功能測試 https://support.zoom.us/hc/zh-tw/articles/206476093-Enabling-breakout-rooms - 認識一位朋友 - 什麼興趣? - 為什麼想了解 Docker? - 其他新鮮事? - 介紹這位你認識的朋友 - 邀請大家分享 Docker 經驗與需求 --- ## 出場人物 - 所有的與會成員 - 伴1:[Fly(不賴)](https://fb.me/flyism) - 伴2/3:饅頭/石頭 --- ## 伴學目標 - 讓任何人都可以在自己電腦執行想要的數位服務 - 你就是那個任何人,可以想想要玩什麼服務 - 交流理解的 Docker 原理 - 整合進入自己的長期專案? --- ## 不賴的 Docker 經驗 - 利用中研院虛擬主機上跑它來執行機器學習作台語語音辨識實驗 - 機中機中機中機……的概念 --- ## Why Docker - 快、乾淨、簡單 https://ithelp.ithome.com.tw/articles/10190614 --- ### 一些好處 * 持續整合的:Docker 讓環境統一變得更容易,這有助於設計持續整合、持續部署的架構。 * 大禮包:只要雲端服務或機器支援 Docker,就能運行 Docker 包裝好的服務。 * 好版控:Docker 使用 Dockerfile 的純文字檔做為建置 image 的來源,這代表 Docker 實現了環境即程式碼(Infrastructure-as-code,IaC),環境資訊可以被版控系統記錄。 * 輕:同為虛擬化技術,Docker(或指 container)的資源使用率較 VM 好,它直接跟底層共用作業系統,不需中間再隔一層作業系統虛擬層,因此啟動 container 非常快。 * 熱門:Docker 應用場景橫跨開發與維運,也是 DevOps 熱門技能之一。 https://ithelp.ithome.com.tw/articles/10237506 --- ## 嘿!安裝 Docker 來相陪 (30 mins) - 來以作業系統分組互助吧 - 主持人遊走各系統群交流經驗 --- 安裝 Docker https://docs.docker.com/desktop/ https://ithelp.ithome.com.tw/articles/10238198 https://ithelp.ithome.com.tw/articles/10201630 ~~虛擬機安裝 https://ithelp.ithome.com.tw/articles/10193928~~ ### MAC 裝完即用 ``` brew cask install docker ``` ### WINDOWS 可能會碰到的坑 - 要裝服務 Hyper-v ~~- 可使用虛擬機安裝(過時) 有時候因為某些理由,可能會不想或無法(如 Windows 7)在原生系統上安裝 Docker,這時可以考慮使用虛擬機安裝。 https://ithelp.ithome.com.tw/articles/10238198~~ ### LINUX (todo) 注意:必須要是 64-bit 版本才能運行 Docker。 ``` sudo curl -fsSL https://get.docker.com/ | sh sudo usermod -aG docker your-user ``` --- ## 嘿!三三兩兩來研究想一鍵啟動服務吧 一行指令快速啟動你要的服務 - 以下搜集實用的 self-host services 可以找一個來試試,到 Sli.do 投下你想架的服務吧 - 找到想要的服務 - 閱讀文件 - 執行!就這麼容易(嗎?) https://github.com/relink2013/Awesome-Self-hosting-for-the-whole-family --- ## 一些 Image 範例 - Blynk server 控制版服務 - livego server 網路串流 - jitsi 視訊 - hackmd 社群版 - https://hackmd.io/c/codimd-documentation/%2Fs%2Fcodimd-docker-deployment - opencart - https://hub.docker.com/r/bitnami/opencart/ - https://blog.maki0419.com/2020/08/docker-opencart.html - wordpress - https://github.com/bitnami/bitnami-docker-wordpress - Rails web server 網站 - https://github.com/bitnami/bitnami-docker-rails - https://github.com/ledermann/docker-rails --- ## 技術原理(如果有興趣了解再看下去) ### 嘿!Docker - 邀請大家分享對 Docker 技術面認知 --- Docker 包括三個基本概念 : 映像檔(Image)唯讀映像檔,可堆疊的貨櫃 容器(Container) image 執行起來的 process,船運行程 倉庫(Repository)存放處,港口倉庫 --- 另一個與 repository 很像,但容易混用的名詞為 Registry,後者涵蓋範圍更廣,包含了更多 repository 與身分驗證功能等,通常比較常討論的也是 registry。 目前 Docker 預設的 registry 為 DockerHub,大多數程式或服務的 image 都能在上面找得到。 https://hub.docker.com ,港口 --- Image、container、repository 之間的關係就像光碟一樣:早期世紀帝國等光碟遊戲,會需要搭配其他可讀寫空間(如硬碟),才有辦法執行。 Image 像光碟片一樣,唯讀且不能獨立執行 Container 像硬碟一樣,可讀可寫可執行 Repository 則是光碟盒,而 Registry 則是像光碟零售商 https://ithelp.ithome.com.tw/articles/10238216 --- ![](https://i.imgur.com/2H4XMVp.png) https://ithelp.ithome.com.tw/articles/10238216 --- ## 玩映像檔 Image ``` 拉 image docker pull hello-world 求救 docker help ``` --- ``` docker run 用來執行 container docker logs 用來查看 container 的 log 訊息 docker ps 用來顯示有哪些container 在執行,如果下-a參數把沒有執行的列出來 docker rm 刪除 container docker rmi 刪除 Docker Image # 使用 CONTAINER ID: 6d7e00198a56 或 NAMES: relaxed_bhabha 皆可 docker rm 6d7e00198a56 ``` --- ## 玩容器 Container ``` docker run -it ubuntu /bin/bash apt-get update apt-get install -y apache2 service apache2 start ``` https://ithelp.ithome.com.tw/articles/10190921 -i|--interactive 和 -t|--tty --- ## docker exec VS docker run docker run 與 docker exec 做的事很相似,決定性差異在於:docker run 會產生新的 container,而 docker exec 需要運行中的 container。 --- ## 玩 registry `docker run -d -p 5000:5000 -v /home/user1/storage:/var/lib/registry --name registry registry:2` --- ## Image 匯出與讀取 ``` 從一台電腦存image docker save -o hello-world.tar hello-world 到另台電腦可以 docker load -i hello-world ``` --- ## Docker Volume 處理資料 ![](https://i.imgur.com/snJbolN.png) 在預設的Docker daemon下,我們常會遇到幾種情況: * 當該容器不再存在時,數據將不會持久保存,並且如果另一個Process需要它,則可能很難從容器中取出數據。 * 容器的可寫層與運行容器的主機緊密耦合。您不能輕易地將數據移動到其他地方。 * 寫入容器的可寫層需要 存儲驅動程序來管理文件系統。存儲驅動程序使用Linux內核提供聯合文件系統。與使用直接寫入主機文件系統的數據卷相比,這種額外的抽象降低了性能 。 --- 在使用 docker run 指令時,指定 -v 參數,使得實體主機的資料夾路徑 Mapping 到 Container 的資料夾路徑,指令如下 ``` docker run -it -v /home/user1/storage:/storage centos /bin/bash ``` /home/user1/storage 是實體主機的資料夾路徑 Mapping 到 Container 裡面的 /storage 資料夾路徑。 https://ithelp.ithome.com.tw/articles/10192397 https://ithelp.ithome.com.tw/articles/10241922 --- ## network Container是個封閉的空間,但難免有些功能開發是需要與其他Containers甚至是外界串接的,因此Docker network因應不同需求發展出了多種類別的network https://ithelp.ithome.com.tw/articles/10242460 --- ## docker-compose 處理多個 Container ![](https://ithelp.ithome.com.tw/upload/images/20200916/20129737SAKXpErjiV.png) --- 想要彈性地處理更多子服務,可以了解 Docker-compose 參見 https://g0v.hackmd.io/65RtkztoTDuDVreqtFHxtQ#%E4%B8%BB%E8%A6%81%E7%B5%90%E6%A7%8B%E8%AA%AA%E6%98%8E https://ithelp.ithome.com.tw/articles/10194183 https://ithelp.ithome.com.tw/articles/10243618 --- ## 查看 Docker Container 的資源使用狀態 ``` docker stats nginx1 nginx2 限制 ram 的使用 docker run --memory 512MB --name nginx3 -d nginx 限制 CPU 的使用 docker run --cpu-period=1000000 --cpu-quota=500000 --name cputest2 -it centos /bin/bash ``` --- ```-c / —cpus``` 原本預設值為1024, 一半即為512,是相對值,佔用主機一半cpu資源 https://ithelp.ithome.com.tw/articles/10243101 --- ## Container 應用 https://ithelp.ithome.com.tw/articles/10242637 --- ## Docker build / Dockerfile to Image https://ithelp.ithome.com.tw/articles/10244280 using cache https://ithelp.ithome.com.tw/articles/10246065 https://ithelp.ithome.com.tw/articles/10240510 --- --- ## 可能的坑 - 執行權限 https://ithelp.ithome.com.tw/articles/10190824 - 如果不要停止 container 而要退出 docker container 的terminal 需要輸入ctrl + p之後再輸入 ctrl + q 的按鍵,就不會把 container 關閉。 --- ## 非伺服器也能對外開放服務,反向代理 反向代理讓你的桌機自架服務可以快速對外開放 - 徵求對反向代理有經驗的朋友分享 --- ### Ngrok - https://ngrok.com/ --- ### More... - https://github.com/anderspitman/awesome-tunneling --- ### localtunnel https://github.com/localtunnel/localtunnel --- ## One more thing - 編輯器外掛 Vscode + docker --- ## 參考 https://g0v.hackmd.io/@MRLyM3ynSfmNj1QrR_csrQ/SJx85m828 https://hackmd.io/v1jFG5KhTnKX5gGKjtf8lg https://www.osboxes.org/virtualbox-images/ 為各種框架 build image https://ithelp.ithome.com.tw/articles/10247679 --- # 好吧,你說你只是想要簡單架服務? 連 Docker 都不用學,直接在 VPS 上快速啟用想要的服務(我是不是太晚講? XD) https://www.youtube.com/watch?v=D1soV_Ff7uk

    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