Roy Lin
    • 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
    • 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
    • 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 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
  • 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
    # Docker 入門與實戰 [TOC] ## 1.1 什麼是Docker 1. 基於Go語言實現的**雲端技術開源專案** 2. Docker引擎的基礎是Linux容器(LXC)技術。 3. 提供各種容器管理工具(如分派、版本管理等)。 4. 使用者操作Docker容器,就像操作<font color=red>**一個輕量級的虛擬機**。</font> 5. ## 1.2 為什麼要使用Docker 1. 伺服器搬移往往需要重新部署和設定調整。Docker提供把應用程式包在容器裡,搬移到其他伺服器可以直接啟動 2. Docker幾乎可以再任意的平台上運行,包括實體機、虛擬機、公有私有雲、個人電腦、伺服器等。 3. 和虛擬器比較:較快、所需資源需求少、類似git的簡單操作、透過dockerfile設定檔彈性高。 ## 2.1 基本概念 - 映像檔(Image) 可將它視為一個專屬於Docker引擎的**唯讀**模板,包含了檔案系統。 例如:一個Ubuntu映像檔(包含一個完整的Ubuntu環境)等。 - Docker容器(Container) 類似一個輕量級沙箱,Docker放用容器來運行和隔離應用, 容器是用Image所創造出來的Instance(執行實力),可以將其建立、開始、停止、刪除 可以把容器看作一個簡易版的Linux系統環境 - Docker Repository(倉庫) Docker集中存放Image的場所。 分為公開和私有兩種形式。 例如:Docker hub ## 2.2 安裝Docker ## 3.1 取得Image 取得最新的Ubuntu作業系統映像檔範例 ```shell= sudo docker pull ubuntu sudo docker pull ubuntu:14:04 #指定版本 ``` 下載後,利用該Image建立一個容器,在其中執行bash程式 ```shell= sudo docker run -t -i ubuntu /bin/bash root@fe7fc4bd8fc9:/# ``` ## 3.2 查看Image資訊 各欄 - 倉庫來源 - Image標籤資訊 - Image ID號 - 建立時間(SHA-1 Hash針對Image做checksum的唯一編碼)。 - Image size ```shell= sudo docker images # 查看有什麼Image(同一個有別名的都會列出來) sudo docker inspect [ID] # 查看完整資訊 => JSON ``` ## 3.3 搜尋Image ```shell= sudo docker search mysql # 搜尋具有mysql關鍵字的Image(搜尋玩就可以知道要載哪一個了?) ``` ## 3.4 刪除Image ```shell= sudo docker rmi [TIMAGE ID or Tag Name] ``` 查看**本機**上存在的Image ```shell= sudo docker ps -a ``` Image仍在使用無法刪除,強制刪除(使用-f參數)(暴力不推薦) ```shell= sudo docker rmi -f ubuntu ``` 先刪掉該Image相關的Container(好的作法) ```shell= sudo docker rm e81 # [Container ID的前幾碼] ``` ## 3.5 建立Image 啟動一個Image => 進行修改(比如新增一個test檔)=> commit建立新的Image ```shell= $ sudo docker run -ti ubuntu:14.04 /bin/bash root@a925cb40b3f0:/# touch test root@a925cb40b3f0:/# exit $ sudo docker commit -m "Added a new file" -a "author info" a925cb40b3f0 test $ sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE test latest a925cb40b3f0 4 seconds ago 225.4 MB ``` ## 3.6 儲存及載入Image 把本機Image另存為.tar檔 ```shell= sudo docker save -o ubuntu_14.04.tar ubuntu:14.04 ``` 載入 ```shell= sudo docker load < ubuntu_14.04.tar ``` 儲存載入並傳到雲端 ```shell= sudo docker save ubuntu:latest | ssh ubuntu@REMOTE-SERVER sudo docker load ``` ## 3.7 上傳映像檔 傳到Docker Hub 把本機的Image加新標籤在上傳 ```shell= sudo docker tag test:latest user/test:latest sudo docker push user/test:latest # push 之後會請你login ``` ## 4.1 建立Container ```shell= docker run --name createAContainerName -d -p 8080:80 myImageName:myImageTags # -d 是讓docker在後端運行 ``` ## push 上去dockerhub [參考資料](https://ithelp.ithome.com.tw/articles/10192824) ```shell= ```

    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