docker 自架服務不求人
安裝 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
裝完即用
brew cask install docker
可能會碰到的坑
注意:必須要是 64-bit 版本才能運行 Docker。
sudo curl -fsSL https://get.docker.com/ | sh
sudo usermod -aG docker your-user
一行指令快速啟動你要的服務
Docker 包括三個基本概念 :
映像檔(Image)唯讀映像檔,可堆疊的貨櫃
容器(Container) image 執行起來的 process,船運行程
倉庫(Repository)存放處,港口倉庫
另一個與 repository 很像,但容易混用的名詞為 Registry,後者涵蓋範圍更廣,包含了更多 repository 與身分驗證功能等,通常比較常討論的也是 registry。
目前 Docker 預設的 registry 為 DockerHub,大多數程式或服務的 image 都能在上面找得到。
Image、container、repository 之間的關係就像光碟一樣:早期世紀帝國等光碟遊戲,會需要搭配其他可讀寫空間(如硬碟),才有辦法執行。
Image 像光碟片一樣,唯讀且不能獨立執行
Container 像硬碟一樣,可讀可寫可執行
Repository 則是光碟盒,而 Registry 則是像光碟零售商
https://ithelp.ithome.com.tw/articles/10238216
https://ithelp.ithome.com.tw/articles/10238216
拉 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
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 run 與 docker exec 做的事很相似,決定性差異在於:docker run 會產生新的 container,而 docker exec 需要運行中的 container。
docker run -d -p 5000:5000 -v /home/user1/storage:/var/lib/registry --name registry registry:2
從一台電腦存image
docker save -o hello-world.tar hello-world
到另台電腦可以
docker load -i hello-world
在預設的Docker daemon下,我們常會遇到幾種情況:
在使用 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
Container是個封閉的空間,但難免有些功能開發是需要與其他Containers甚至是外界串接的,因此Docker network因應不同需求發展出了多種類別的network
https://ithelp.ithome.com.tw/articles/10242460
想要彈性地處理更多子服務,可以了解 Docker-compose
參見
https://g0v.hackmd.io/65RtkztoTDuDVreqtFHxtQ#主要結構說明
https://ithelp.ithome.com.tw/articles/10194183
https://ithelp.ithome.com.tw/articles/10243618
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
https://ithelp.ithome.com.tw/articles/10242637
https://ithelp.ithome.com.tw/articles/10244280
using cache
https://ithelp.ithome.com.tw/articles/10246065
https://ithelp.ithome.com.tw/articles/10240510
反向代理讓你的桌機自架服務可以快速對外開放
https://github.com/localtunnel/localtunnel
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
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
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.
Do you want to remove this version name and description?
Syncing