# 20201006 映像與倉庫 (三)

## 課堂資料

#### 如何備份 Docker Image 為 tar 檔：

{% embed url="<https://ithelp.ithome.com.tw/articles/10191387>" %}

#### Docker Harbor 安裝：

{% embed url="<https://github.com/goharbor/harbor/releases/tag/v1.10.0>" %}

{% embed url="<http://csie.nqu.edu.tw/smallko/harbor1.9.0.tgz>" %}

#### Docker容器倉庫Harbor的安裝部署：

{% embed url="<https://learnku.com/articles/29884>" %}

{% embed url="<https://kknews.cc/zh-tw/code/5n9poj6.html>" %}

{% embed url="<https://godleon.github.io/blog/Docker/docker-network-bridge/>" %}

### Harbor&#x20;

#### Harbor 的安裝部署

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

```
systemctl status sshd
```

```
docker save -o myhttpd.tar [鏡像ID]
```

![](/files/-MO_8Z84CFADUmYQsjmE)

```
scp myhttpd.tar user@192.168.8.130:/home/user
```

### [下載安裝包](https://github.com/goharbor/harbor/releases/tag/v1.10.0)

```
ls
```

```
mv harbor1.9.0.tgz /root
```

```
ls
```

```
cd
```

![](/files/-MObO8JyHwaGcUiZouaC)

### 安裝和配置

```
tar xvf harbor1.9.0.tgz
```

```
cd harbor
```

```
ls
```

```
gedit harbor.yml &
```

![](/files/-MObPI8lxbok7eL85QIh)

{% hint style="danger" %}
hostname 改為`192.168.8.129`

harbor\_adnim\_password 改為 hb12345
{% endhint %}

![](/files/-MO_LRsdzx_Hbl_E1cJQ)

#### 執行安裝程序

```
sh install.sh
```

![](/files/-MObQI0jdy1SqdJeHpkc)

![](/files/-MOfYEJ2-ozYur2N1Pot)

{% hint style="info" %}
帳號：admin

密碼：Harbor12345
{% endhint %}
{% endtab %}

{% tab title="vm2" %}

```
ls
```

```
docker load -i myhttpd.tar
```

```
docker images
```

```
docker tag [鏡像ID] [xiaoji850312/鏡像名稱]:1.0
```

```
docker run -itd -p 8080:80 xiaoji850312/httpd:1.0
```

```
curl 127.0.0.1:8080
```

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

### Docker Bridge Network

#### Bridge Network 架構

![](/files/-MOmYH5jsZB7l0USMvil)

## 課堂練習

### Harbor 操作

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

> #### 抓取 harbor 密碼資料

```
cat harbor.yml | grep -i pass
```

![](/files/-MOfZF1RTMA-p-MY-yor)

```
docker-compose up -d
```

* `up -d`：重新啟動
* `-d`：背景執行
  {% endtab %}

{% tab title="vm2" %}

```
docker tag [鏡像ID] 192.168.8.129/libabry/busybox:latest
```

![](/files/-MOmE8TQvu9DludHaGn0)

> #### 設定登入配置

```
gedit /etc/docker/daemon.json
```

![](/files/-MOmGosCMpSTEpdHNvJp)

> #### 進入`daemon.json`編輯

```
{
"insecure-registries":["192.168.8.129"]
}
```

![](/files/-MOmGduk3HShGz65XHxD)

> #### 啟動`daemon`

```
systemctl daemon-reload
```

```
systemctl restart docker
```

> #### 登入 harbor

```
docker login 192.168.8.129
```

{% hint style="info" %}
帳號：admin

密碼：Harbor12345
{% endhint %}

![](/files/-MOmUp5PnYLQ5WQe1GwK)

```
docker push 192.168.8.129/library/busybox:latest
```

> #### 查詢關鍵字為`busybox`的鏡像檔

```
docker images | grep busyboxgrep 
```

* `grep`：查詢關鍵字

```
docker pull 192.168.8.129/library/busybox:latest
```

{% endtab %}
{% endtabs %}

### Docker Bridge Network

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

> #### 檢視目前 Docker Network 狀態

```
docker network ls
```

> #### 建立 container

* 第一種網路用法 ( none )：不要啟動任何網路

```
docker run -it --network=none busybox:latest sh 
```

```
ifconfig
```

```
exit
```

![](/files/-MOmabGH5c8cmpugVxdo)

* 第二種網路用法 ( host )：防攻擊、偵測

{% hint style="info" %}
與主機看到的是一樣的
{% endhint %}

```
docker run -it --network=host busybox:latest sh 
```

```
ifconfig
```

```
exit
```

![](/files/-MOmavI9stxDyJz7Zbxc)

* 第三種網路用法 \[( bridge )預設網路類型 ]：docker0

```
docker run -it --network=bridge --name a1 busybox:latest sh 
```

```
ifconfig
```

```
ping 172.17.0.1
```

```
exit
```

![](/files/-MOmbkk_0SwIIgOVahOw)

```
docker run -it --network=bridge --name a2 busybox:latest sh 
```

```
ifconfig
```

```
exit
```

```
docker run -it --network=bridge --name a3 busybox:latest sh 
```

```
ifconfig
```

```
exit
```

```
docker inspect a1
```

![](/files/-MOmd-_MSthEmdJvkJMV)

> #### 查看`bridge`

```
brctl show
```

> #### 自訂 docker network

```
docker network create --driver bridge mynet
```

```
docker network ls
```

> #### 建立 container

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

```
ifconfig
```

```
exit
```

```
docker network connect bridge a4
```

```
docker network disconnect bridge a4
```

![](/files/-MOmhYkVPopunREY1bnN)

> #### 測試 container 網路

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

```
docker exec -it a5 sh
```

![](/files/-MOmjIF68VEm_y2dunaE)
{% 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/ying-xiang-yu-cang-ku-er.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.
