# 啟動容器

## **容器的基本操作**

### **exit (離開容器)**

**離開互動界面:使用者透過 exit 命令或 Ctrl+d 來退出終端時，所建立的容器立刻終止**<br>

### **docker ps**

**可以發現執行中的容器。**<br>

### **docker ps -a**

**要檢視已經被中止的容器，請加入 -a 的選項**<br>

### **docker start 容器**

**處於終止狀態的容器，可以透過 docker start 命令來重新啟動**<br>

**docker start firstubuntu**

**docker ps(可以看到正在執行的容器)**

\
**不過，此時容器已於背景執行，若要再次進入互動界面，請使用 attach**<br>

### **docker attach 容器**

**docker attach firstubuntu**\
**此時，又再次進入容器之中，你可以對容器進行一些操作，就像你在操作一般的ubuntu一樣**

**按下 ctrl + P 然後 ctrl + Q 跳離容器，讓它繼續在背景執行**

### **docker於背景中執行**

**大多的時候，需要讓 Docker 容器在背景執行。此時，可以透過新增 -d 參數來實作。**\ <br>

**docker run -itd --name secondubuntu ubuntu**<br>

**這樣，就會產生名為secondubuntu的容器，並於背景中執行**<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/cao-zuo-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.
