docker_practice/container/daemon.md
Ensky Lin a795bf863a 修正多個用詞
"s/程序/程式/g" "s/性能/效能/g" "s/如下/以下/g" "s/加載/載入/g" "s/獲取/取得/g" "s/服務器/伺服器/g" "s/信息/訊息/g" "s/註釋/註解/g" "s/裏/裡/g" "s/構建/建立/g" "s/配置/設定/g"
2014-11-24 22:54:30 +08:00

25 lines
854 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

##守護態執行
更多的時候,需要讓 Docker 容器在後臺以守護態Daemonized形式執行。此時可以透過新增 `-d` 參數來實做。
例以下面的命令會在後臺執行容器。
```
$ sudo docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
1e5535038e285177d5214659a068137486f96ee5c2e85a4ac52dc83f2ebe4147
```
容器啟動後會返回一個唯一的 id也可以透過 `docker ps` 命令來查看容器訊息。
```
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e5535038e28 ubuntu:14.04 /bin/sh -c 'while tr 2 minutes ago Up 1 minute insane_babbage
```
要取得容器的輸出訊息,可以透過 `docker logs` 命令。
```
$ sudo docker logs insane_babbage
hello world
hello world
hello world
. . .
```