# 建立容器

### **docker run建立映像檔容器**

**Docker 利用容器來執行應用。**\
**容器是從映像檔建立的執行。它可以被啟動、開始、停止、刪除。每個容器都是相互隔離的、保證安全的平台（使用核心namespace與cgroup來達成）**<br>

**hello 我的 docker 容器**

**docker run hello-world**

<div align="left"><img src="https://lh3.googleusercontent.com/fDJiqjYo16aTLSQagkq1Z4agyKENYe6JkyHJVkRgkE53krcuDomtrLJJVnfZe6_ZKd2BI1tO4Yv0BPxyxj3Nb0zn1rrfHtYkiUbgXqOI9QlX_4vDziOk_MttcUBBJx3CVN2ntNzQ" alt=""></div>

**docker run -it --name firstubuntu ubuntu**\
**root\@4eb602fae6d4:/#（此處已經進入容器的互動界面）**<br>

**其中，-t 選項讓Docker分配一個虛擬終端（pseudo-tty）並綁定到容器的標準輸入上， -i 則讓容器的標準輸入保持打開(interactive)**\
**root\@4eb602fae6d4:/# ps**\
&#x20; **PID TTY          TIME CMD**\
&#x20;   **1 pts/0    00:00:00 bash**\
&#x20;  **10 pts/0    00:00:00 ps**\
**容器的核心為所執行的應用程式，所需要的資源都是應用程式執行所必需的。除此之外，並沒有其它的資源。可以在虛擬終端中利用 ps 來查看程式訊息**

**可以發現在此隔離空間中，只用到bash的程序，並不會像VM需求許多的程序來啟動，這種特點使得 Docker 對資源的使用率極高，是貨真價實的輕量級虛擬化**<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kawsing.gitbook.io/opensystem/docker-cong-an-zhuang-dao-ying-yong-ru-men-pian/jian-li-rong-qi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
