- Dosh 為系計中開發的 Docker shell,您可以使用此 shell 運行個人容器,並擁有 root 權限。
- 您可以將工作站家目錄掛載進容器內檔案系統之
/home/<username>
下。 - 您於容器內所有的操作將於容器被刪除時全數消失。您可以將必要資料儲存於家目錄中防止遺失。
Dosh 資源限制
以下為容器之資源限制,如超過限制將被自動刪除。容器不再使用時請刪除。
Resources | Limit |
---|---|
CPU | 1 CPU |
Memory | 512 MiB |
Storage | 2 GiB |
Process | 100 |
上述之 Storage 大小並不計入工作站家目錄中的資料。
Dosh 問題回報
目前 Dosh 仍持續開發中,若有使用上的問題,歡迎來信告知。
Dosh 使用教學
在任一 linux 工作站上執行以下指令,即可進入 docker shell。
dosh
Dosh 指令操作教學
普通指令
您可以使用之一般指令包含 cd
cat
ls
less
。
建立容器
可以使用 create
指令建立容器。若不給予任何參數,系統將會進入 interactive 問答模式,如下示例:
user@dosh:~$ create
✔ Enter container name: test-container
✔ Image name: ubuntu
✔ Mount home directory? (y/N) true
? When should your container be restarted? …
▸ Never
Only when my container fails
Any time my container fails or succeeds
您也可以使用 non-interactive 的方式建立容器。以下示範建立一個名為 test-container
之 Ubuntu 容器。
user@dosh:~$ create test-container -i ubuntu
關於更多使用說明,可以 create -h
查詢。
進入容器
您可以使用 attach [container-name]
指令進入指定容器的 shell。
user@dosh:~$ attach test-container
root@test-container:/home/user$ whoami
root
root@test-container:/home/user$
在容器內執行指令
您可以使用 exec
指令在容器內執行指令。若不給予任何參數,系統將會進入 interactive 問答模式,如下示例:
-
選擇要執行指令的容器。
user@dosh:~$ exec ? Which container: … ▸ test-container ▸ another-test-container
-
輸入 command。連按兩次 ENTER(即輸入一個空行)表示指令結束。
user@dosh:~$ exec ✔ Which container: · test-container ---------------- BEGIN DOSH SCRIPT ---------------- ? whoami && echo hello world uname -r date > 1>&2 ----------------- END DOSH SCRIPT -----------------
-
Dosh 將會印出結果。
user@dosh:~$ exec ✔ Which container: · test-container ✔ whoami && echo helloworld uname -r date 1>&2 root hello world 4.18.0-305.17.1.el8_4.x86_64
指令 exec
有非常豐富多樣的使用方式,您可以 exec -h
參考詳細的說明。
列舉容器
您可以使用 ps
列舉所有運行中的容器。若要列舉包含非運行中之容器,可以加上 -a
參數。
user@dosh:~$ ps
┌──────────────────────┬─────────┬─────────────────────────────┬──────────┬──────────────┐
│ Container │ Author │ Image │ State │ Created At │
├──────────────────────┼─────────┼─────────────────────────────┼──────────┼──────────────┤
│ test-container │ user │ docker.io/ubuntu:latest │ Running │ 15:12:41 │
└──────────────────────┴─────────┴─────────────────────────────┴──────────┴──────────────┘
關於更多使用說明,可以 ps -h
查詢。
刪除容器
您可以使用 kill [container-name]
刪除容器。
user@dosh:~$ kill test-container
Killing...
Killed: test-container
關於更多使用說明,可以 kill -h
查詢。
查詢容器 logs
您可以使用 logs [container-name]
查詢容器之 logs。
logs test-container
您可以使用參數 -f
即時更新 logs。
關於更多使用說明,可以 logs -h
查詢。
登入 Dockerhub 並製作 Docker Image
您可以自備 Dockerfile 以製作容器,然後將其發布至 Dockerhub。製作容器所需要之本地檔案需位於您的家目錄內。
您可以使用 login
指令登入 Dockerhub,Dosh 將詢問您的 Dockerhub 帳號與密碼。
user@dosh:~$ login
✔ Username: nycucs
✔ Password:
You are logged in.
當您登入後,就可以使用 build
指令建立容器。假設您有一 Dockerfile 置於 ~/mycontainer/Dockerfile
,您可以如下方式將其製作成 image 並發布至 Dockerhub 之 nycucs/helloworld
repository。注意 nycucs
需為您已登入之 Dockerhub 帳號。
user@dosh:~$ build -r nycucs/helloworld ./mycontainer/Dockerfile
Building image...
Done.
您可以使用 logout
指令登出 Dockerhub。
關於更多使用說明,可以 login -h
logout -h
build -h
查詢。
使用說明
您可以 help
指令查閱 Dosh 的完整使用說明。
關於個別功能之說明,可以 [command] -h
查詢該功能之使用方法,例如:
user@dosh:~$ exec -h
Create a container.
Usage
dosh create [options] <container>
Options
-i, --image image-name From which image the container is built. Default to the container name.
-g, --ignore-existing Suppress error message if a running container with same name already exists,
even if the container image mismatches.
-f, --force If an running container with same name exists, kill it and try again. This
option overrides -g.
-x, --restart never|fail|always Determine when the container should be restarted. Default to `never`.
-M, --no-mount Do not mount home directory under the container. This action cannot be undone
after the container is created.
-q, --quiet Do not show progress bar. Default set in non-interactive mode.
-h, --help Show this message.
在 Dosh 外操作容器
除了使用 dosh
指令進入 docker shell 操作容器之外,您也可以在工作站撰寫自動化腳本操作容器資料,使用方式如下:
dosh [commands...]
以下示範一使用者創建一名為 hello-vim
之 Ubuntu 容器,並在其中安裝 vim 的自動化腳本。
#!/bin/bash
readonly CONTAINER_NAME='hello-vim'
readonly IMAGE_NAME='ubuntu:bionic'
readonly VIM_INSTALLATION_COMMAND='apt-get update -y && apt-get install vim -y'
dosh kill -f -q $CONTAINER_NAME && \
dosh create $CONTAINER_NAME -i $IMAGE_NAME -x never -q && \
dosh exec -s $CONTAINER_NAME -q "VIM_INSTALLATION_COMMAND"