> For the complete documentation index, see [llms.txt](https://anida-huang.gitbook.io/cloud-communication/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anida-huang.gitbook.io/cloud-communication/qi-zhong/guan-li-he-shi-yong-rong-qi-yi.md).

# 20201013 管理和使用容器

## 課堂資料

#### Docker -- 從入門到實踐 --容器互連：

{% embed url="<https://philipzheng.gitbook.io/docker_practice/network/linking>" %}

#### Docker 與 DNS：

{% embed url="<https://dotblogs.com.tw/grassshrimp_tech_intern/2016/06/18/071957>" %}

{% embed url="<https://www.kubernetes.org.cn/5883.html>" %}

{% embed url="<https://blog.kevinyang.net/2020/08/03/docker-101-note-3/>" %}

{% embed url="<https://www.jinnsblog.com/2018/12/docker-dockerfile-guide.html>" %}

{% embed url="<https://github.com/kstaken/dockerfile-examples>" %}

## 課堂練習

### 容器使用

#### Docker Link 使用

{% tabs %}
{% tab title="vm1 - c1" %}

```
docker run -it --name c1 busybox sh
```

![c1](/files/-MJV_XXBpMNjcXeO_y2L)

> #### 查詢 IP&#x20;

```
ifconfig
```

{% endtab %}

{% tab title="vm1 - c2" %}

```
docker run -it --name c2 --link c1:c1 busybox sh
```

![c2](/files/-MJV__AZjAvO7amOrAvV)

> #### 查詢 IP&#x20;

```
ifconfig
```

> #### c2 直接 ping c1

```
ping c1
```

![c2](/files/-MJVaej9swDZtEr9zwmy)

{% hint style="info" %}
c2 能直接 ping c1，c1 則不行直接 ping c2
{% endhint %}

```
cat /etc/hosts
```

![](/files/-MJVdg_fJa2HKbaFUBUB)
{% endtab %}

{% tab title="vm1 - c3" %}

```
docker run -it --name c3 --network mynet busybox sh
```

```
docker run -it --name c4 --network mynet busybox sh
```

![](/files/-MOmpTLsY16OHqRnud20)

```
cat /etc/hosts
```

![](/files/-MOmpsIyBVy3_7iklnp6)
{% endtab %}
{% endtabs %}

### Docker 與 DNS

```
docker run -d --net=mynet --name web training/webapp
```

![](/files/-MOmu4zhU6fYxG8_MaWG)

```
docker exec -it web bash
```

```
ping db
```

```
exit
```

![](/files/-MOmuZH2AtMWw6YeeZPf)

```
docker network ls
```

```
docker run -d --net=mynet --name db training/postgres
```

```
docker run -d --net=mynet --name web training/webapp
```

```
docker ps
```

![](/files/-MOmv_RPZL1fCXrKlDzd)

```
docker exec -it web bash
```

```
ping web
```

```
ping db
```

![](/files/-MOmw4Ntu2OzekwwFb2L)

```
exit
```

```
cd
```

```
mkdir -p /data
```

```
cd /data
```

```
echo "hi" > hi.htm
```

```
cd
```

```
docker run -itd --name myweb -p 8080:80 -v /data:/usr/local/apache2/htdocs httpd
```

![](/files/-MOmxbz9ZJSmUgBzWxB7)

![](/files/-MOmxWOI__0--B8sT1ig)

```
docker run -itd --name myweb1 -p 8081:80 -v /usr/local/apache2/htdocs httpd
```

```
docker inspect myweb1
```

![](/files/-MOmyAYO-ju-x-hR2VyJ)

```
cd ["mounts":Source]
```

```
echo "hello" > hello.htm
```

![](/files/-MOmz3djIsxVGPjJsD8J)

![](/files/-MOmyxlULPyt5XJfL1zO)

```
docker volume ls
```

```
docker volume create --name webdata
```

```
docker volume ls
```

![](/files/-MOn-SmtFkCrDDHQS_ak)

```
docker run -itd --name myweb2 -p 8082:80 -v webdata:/usr/local/apache2/htdocs httpd
```

```
docker inspect [容器ID]
```

![](/files/-MOn-uBEyF3YrE5uh9FE)

```
cd ["mounts":Source]
```

```
echo "1" > 1.htm
```

```
echo "2" > 2.htm
```

![](/files/-MOn0QEYMiK2CuZBdtQh)

![](/files/-MOn0WvgVpZ3UepwuRT4)

```
docker run -itd --name myweb3 -p 8083:80 -v webdata:/usr/local/apache2/htdocs httpd
```

![](/files/-MOn0jZfZWQ7iyiKc12q)

![](/files/-MOn0oigVxzqebe9Vc6f)

```
cd
```

### Portainer ( 圖形化介面 )

> #### Portainer搭建部署

```
docker run -d -p 9000:9000 --restart=always --name portainer -v /var/run/docker.sock:/var/run/docker.sock -v /Users/lee/dev/docker_file/portainer/data:/data docker.io/portainer/portainer
```

![](/files/-MOn22fy5RrnavsuQRjn)

![](/files/-MOn2FVgPwCGne20M0oV)

{% hint style="info" %}
預設密碼：12345678
{% endhint %}

> #### Dashboard

![](/files/-MOn4-V-D3XDXFkkDYnM)

> #### Images
>
> #### Images > Build a New Image

![](/files/-MOn5K1owvIpS_XgVEig)

> #### Build a New Image
>
> #### Web editor

![](/files/-MOn62KaWaSWP5p5DK6y)

![](/files/-MOn6B_RwTLkVctBfxlb)

```
cd /home/user
```

```
docker history [httpd容器ID]
```

```
docker run -it --rm busybox echo "hello"
```

```
cd 
```

{% tabs %}
{% tab title="/test1" %}

```
mkdir test1
```

```
cd test1
```

```
vim Dockerfile
```

![](/files/-MOn9YoCK3lnMQxTs8bD)

![](/files/-MOn9Km6gyNjzYXD6zf0)

```
docker build -t myweb:0.1 .
```

![](/files/-MOnE1BGdCOjViwZ0pMM)

```
docker run -it --rm myweb:0.1 echo "hi"
```

```
docker run -d -p 8085:80 myweb:0.1
```

```
curl 127.0.0.1:8085
```

![](/files/-MOnK60qRF758s4q5Wsz)
{% endtab %}

{% tab title="/home/user" %}

```
docker run -it --rm httpd:latest echo "hi"
```

![](/files/-MOnFPvlPr3j8TtHjjp9)

```
docker ps
```

```
docker run -d -p 8088:80 httpd
```

```
docker ps
```

![](/files/-MOnKoA8cVmRzIcgMpxP)

```
docker stop [容器ID]
```

![](/files/-MOnKy8nufSDk7iG6zEp)
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://anida-huang.gitbook.io/cloud-communication/qi-zhong/guan-li-he-shi-yong-rong-qi-yi.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.
