Aaron Wu
    • 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
    --- title: '關於 Docker 的那檔事 | 建北電資網管傳承' image: https://hackmd.io/_uploads/rJpAHerNn.png --- ###### tags: `建北電資網管傳承` :::info 本筆記由建電一三學術長吳亞倫製作 若有相關疑慮,可以寄信到 [aaronwu0218@gmail.com](mailto:aaronwu0218@gmail.com) 或是 Discord `AaW#2549` 詢問 ::: ## Docker Docker是一個好東西。 他是一個類似於虛擬機的東東,可以十分輕量化的建立一個服務,同時將應用程式安裝在不會影響到原先伺服器的設定。 教學文章: - https://ithelp.ithome.com.tw/articles/10199339 - https://larrylu.blog/step-by-step-dockerize-your-app-ecd8940696f4 我在這邊簡單講一下下我對於Docker的各種理解 ## image 基本上,就是一個公開的東西。 可以把它當作是安裝檔之類的,或是類似於一個github repo。 常見的image有純ubuntu、ubuntu+nginx之類的。也有一些人會透過Dockerfile建立自己應用程式的image並且放在網路上,例如青島OJ。 基本上我們在建立應用程式時,需要先將一個image pull下來。再透過他建立container。 ![](https://hackmd.io/_uploads/r1R5euFDh.png) - `docker image list` : 檢視電腦裡有哪些image ![](https://hackmd.io/_uploads/HJqrZBtwn.png) ## container 就是一著正在執行的,一個類似虛擬機的東東。 可以透過 `docker ps -a` 指令檢視正在執行的 container。 ![](https://hackmd.io/_uploads/rJ21MBYv3.png) ## docker-compose 基本上,我們不太需要自己慢慢的用 docker run 之類的指令來執行docker,由於我們都是使用別人打包好的應用程式,因此我們可以直接以 docker-compose 的相關指令來將一堆docker一次設定好。 教學文章:https://ithelp.ithome.com.tw/articles/10194183 所有docker-compose的相關指令與配置,都會記載在專案資料夾的 `docker-compose.yml` 文件當中。以青島OJ的文件為例: ```yml= version: "3" services: oj-redis: image: redis:4.0-alpine container_name: oj-redis restart: always volumes: - ./data/redis:/data oj-postgres: image: postgres:10-alpine container_name: oj-postgres restart: always volumes: - ./data/postgres:/var/lib/postgresql/data environment: - POSTGRES_DB=onlinejudge - POSTGRES_USER=onlinejudge - POSTGRES_PASSWORD=onlinejudge judge-server: image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/judge_server container_name: judge-server restart: always read_only: true cap_drop: - SETPCAP - MKNOD - NET_BIND_SERVICE - SYS_CHROOT - SETFCAP - FSETID tmpfs: - /tmp volumes: - ./data/backend/test_case:/test_case:ro - ./data/judge_server/log:/log - ./data/judge_server/run:/judger environment: - SERVICE_URL=http://judge-server:8080 - BACKEND_URL=http://oj-backend:8000/api/judge_server_heartbeat/ - TOKEN=CHANGE_THIS # - judger_debug=1 oj-backend: image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/oj_backend container_name: oj-backend restart: always depends_on: - oj-redis - oj-postgres - judge-server volumes: - ./data/backend:/data environment: - POSTGRES_DB=onlinejudge - POSTGRES_USER=onlinejudge - POSTGRES_PASSWORD=onlinejudge - JUDGE_SERVER_TOKEN=CHANGE_THIS - FORCE_HTTPS=1 # - STATIC_CDN_HOST=cdn.oj.com ports: - "0.0.0.0:8000:8000" - "0.0.0.0:1443:1443" ``` 文件中大部分的東西都不用懂。首先我們可以看到的是`services`區段底下的四個大區段:`oj-redis`、`judge-server` 和 `oj-backend`。這分別代表docker-compose會啟動的四個容器。再次注意,一個docker container基本上就是一台虛擬機。 一般來說你們有可能需要動到的只有下列兩個地方。 1. port 區塊 - 以第64行為例,代表的是要將host的8000阜映射到oj-backend這台虛擬機的8000阜 2. volumes - 以第60行為例,代表的是要將host的`./data/backend`資料夾共用到虛擬機的`/data`資料夾。 #### docker-compose 會用到的指令 > 注意,要先cd到有docker-compose.yml的那個資料夾 ```bash docker-compose up -d ``` 執行應用程式,並且detach (在背景中執行) ```bash docker-compose up ``` 執行應用程式,並且顯示log在console當中 ```bash docker-compose build ``` 建立但不執行(up時也會先build) ```bash docker-compose down ``` 停止應用程式 ```bash docker-compose restart ``` 重新啟動運用程式。但注意,此指令並不會更新到你對配置文件做的新跟動。如果有修改yml檔案之類的,請用先down再up的方式重啟。 ## 其他常用指令 ```bash docker exec -it <CONTAINER-NAME> /bin/bash ``` 進入虛擬機的 bash 裡面 ```bash docker ps -a ``` 檢查所有容器的狀態

    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