Jerry Wang
    • 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
    • Make a copy
    • 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 Make a copy 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
    # Docker 入門 ## 三大概念 * image * container * repository 一個 image 可建立多個 container,container 可被啟動,開始,停止,刪除。repository 分為 public 和 private 的,類似 git 的概念。 ### docker 服務 docker engine docker volumes docker networks ## 安裝 刪除舊版 docker ` sudo apt-get remove docker docker-engine docker.io containerd runc` 更新套件 `sudo apt-get update` 安裝必要的套件 `sudo apt-get install \` ` apt-transport-https \` ` ca-certificates \` ` curl \` ` gnupg-agent \` ` software-properties-common` 加上 docker gpg key `curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -` `sudo apt-key fingerprint 0EBFCD88` 加入 docker repository `sudo add-apt-repository \` ` "deb [arch=amd64] https://download.docker.com/linux/ubuntu \` ` $(lsb_release -cs) \` ` stable"` 安裝 docker `sudo apt-get update` `sudo apt-get install docker-ce` 不用 sudo 也可以執行 `sudo usermod -aG docker $(whoami)` ## image 搜尋 image `docker search ubuntu` pull image `docker pull ubuntu:16.04` 列出本地所有 image `docker images` 刪除 image `docker rmi ubuntu:16.04` ### dockerfile dockerfile 中每一條指令會建立一層 image 用 # 寫註解。 FROM 指定用哪個 image 當作基底 ADD/COPY 複製本地檔案到 images `ADD FROM-PATH TO-PATH` ENV `ENV DB_HOST LOCALHOST` `ENV demoPATH="/var/log" demoVer="1.0"` EXPOSE 向外部開放的 port `EXPOSE 5000` RUN 會在建立 image 的過程中執行。 `RUN mkdir -p /home/demo/docker` `RUN apt-get update && \` ` apt-get install ffmpeg -y &&\` ` pip3 install -r /r.txt` `RUN ["apt-get", "install", "python3"]` CMD 為 container 啟動後執行的指令 會被docker run 覆蓋 `CMD echo "This is a test." | wc -` `CMD ["/usr/bin/wc","--help"]` 用 bash 指令替代 CMD 內指定的指令 `docker run -ti nginx bash` ENTRYPOINT 不會被 docker run 覆蓋 `ENTRYPOINT ["executable", "param1", "param2"]` `ENTRYPOINT command param1 param2` 從 dockerfile 產生 image `docker build -f /path/to/a/Dockerfile -t myimage:v3 .` WORKDIR 進入 container 後的 pwd `WORKDIR /app` VOLUME ## container 列出目前執行中的 container `docker ps` 終止狀態的 container 也會列出 `docker ps -a` 新建立並啟動 container 從 image 建立 container,並在其中執行 /bin/bash 指令 也可填入 image id d 表示背景執行 `docker run -tid ubuntu:16.04 /bin/bash` 命名 container name `docker run -p 4000:5000 --name xxxxx -itd ubuntu bash` container 已存在時 `docker start ubuntu` `docker restart ubuntu` `docker stop ubuntu` 取得 container console 輸出的訊息 `docker logs containerID` `docker stats containerID` `docker inspect containerID` container 背景執行後,可以再重新連接上 `docker exec -it alpine1 ip addr show` -> 執行 ip addr show 指令 `docker exec -ti containerid bash` -> 用 exit 離開,仍會在背景執行 `docker attach containerid` -> 用 exit 離開,container 就會關閉。ctrl + p 再 ctrl + q, 就不會關閉 刪除已停止的 container `docker rm containerid` 刪除正在執行的 container `docker kill containerid` ## Docker Network 會產生 networkid `docker network` `docker network --name main_net` `docker network inspect networkid` `docker network ls` `docker run -ti --name container1 --rm --network=main_net ubuntu` ### bridge (default) 預設會產生 docker0 的 network interface (可用 `ifconfig` 檢查) * 在自訂的 docker network 中,container 可以透過 domain name 的方式與其他在同一個 docker network 下的 container 通訊 * 不同 docker network 之間的 container 網路是隔離無法相互通訊的,不論是透過 domain name or IP ## Docker Volume ### 先產生 volume,再掛進 container 會產生 volumeid `docker volume create` `docker volume create --name db-volumeName` 兩個 container 之間可共用資料 `docker run -v volumeid:/foo --name foo -it ubuntu /bin/sh` `docker run -v volumeid:/foo2 --name foo2 -it ubuntu /bin/sh` `docker volume ls` `docker volume inspect volumeid` `docker inspect -f '{{.Mounts}}' containerName` ### 用 Dockfile 產生 `VOLUME /data` ### 用 run 指令產生 掛 volume `docker run -v /data --name foo ubuntu /bin/bash` 掛本機資料夾 `docker run -v /home/admin/data:/data --name foo ubuntu /bin/bash` ## docker compose ### 安裝 `curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o ~/docker-compose` `sudo mv ~/docker-compose /usr/local/bin/docker-compose` `sudo chmod +x /usr/local/bin/docker-compose` `docker-compose.yml` 用 -f 指定特定的dockercompose file --build 重新建構 `docker-compose up -d -f dockercomposefile --build` `docker-compose ps` `docker-compose logs` `docker-compose logs servicename` `docker-compose stop` `docker-compose down` `docker-compose rm` `docker-compose images` `docker-compose top` `docker-compose ps` attach shell,不需要 -it `docker-compose exec servicename bash` ### docker-compose.yaml version 要使用的 docker-compose 版本號 docker-compose 會使用 image or build 來建置docker-compose 基底,有 image 會先使用 image image 要使用的基底image build 直接取 Dockerfile `build .` 指定特殊名稱的 dockerfile `build:` `context: .` `dockerfile: nginx.Dockerfile` ports volumes 可直接掛載本機的檔案到 container 內 or 先宣告在外面,再宣告在services內 宣告建立db_data儲存目錄 `volumes:` `db_data:` `volumes:` `- db_data:/var/lib/mysql` networks 定義 docker networks 先宣告在外面,再宣告在services內 `networks:` `mysql:` `networks:` `- mysql` environment depends_on ## Kubernetes ### deployment 物件 project -> clusters -> nodes (類似 vm) -> pods -> containers ### Service 物件 Pod 之間可以互相溝通,可從外部存取 cluster https://philipzheng.gitbook.io/docker_practice/ https://ithelp.ithome.com.tw/users/20092025/ironman/2603 https://ithelp.ithome.com.tw/users/20111953/ironman/1938 https://godleon.github.io/blog/Docker/docker-network-overview/ https://godleon.github.io/blog/Docker/docker-network-bridge/ https://dotblogs.com.tw/grassshrimp_tech_intern/2016/06/20/194915 http://blog.maxkit.com.tw/2017/03/docker-volume.html https://www.netadmin.com.tw/netadmin/zh-tw/technology/34E092358FA040B2A3DDB9E9597470DF https://www.netadmin.com.tw/netadmin/Author.aspx?Id=222 正向代理和反向代理的區別 雖然正向代理伺服器和反向代理伺服器所處的位置都是客戶端和真實伺服器之間,所做的事情也都是把客戶端的請求轉發給伺服器,再把伺服器的響應轉發給客戶端,但是二者之間還是有一定的差異的。 1、正向代理其實是客戶端的代理,幫助客戶端訪問其無法訪問的伺服器資源。反向代理則是伺服器的代理,幫助伺服器做負載均衡,安全防護等。 2、正向代理一般是客戶端架設的,比如在自己的機器上安裝一個代理軟體。而反向代理一般是伺服器架設的,比如在自己的機器集群中部署一個反向代理伺服器。 3、正向代理中,伺服器不知道真正的客戶端到底是誰,以為訪問自己的就是真實的客戶端。而在反向代理中,客戶端不知道真正的伺服器是誰,以為自己訪問的就是真實的伺服器。 4、正向代理和反向代理的作用和目的不同。正向代理主要是用來解決訪問限制問題。而反向代理則是提供負載均衡、安全防護等作用。二者均能提高訪問速度。

    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