> 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/20200929-ying-xiang-yu-cang-ku-er.md).

# 20200929 映像與倉庫 (二)

## 課堂資料

### None

## 課堂練習

### Part 01.

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

```
docker search httpd
```

![](/files/-MOT0U53s7_O5e_daBl7)

```
docker login
```

```
docker pull centos
```

```
docker images
```

```
cd
```

```
systemctl start sshd
```

{% hint style="success" %}
開啟 PuTTY
{% endhint %}

```
docker pull rackspacedot/python37
```

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

{% tab title="/var/lib/docker" %}

```
cd /var/lib/docker
```

```
cd image
```

```
cd overlay2
```

```
docker images
```

![](/files/-MOY0RZFXpRpDLxUxGk_)

```
docker run -it busybox:latest sh
```

```
ifconfig
```

![](/files/-MOY0hee2z6gddC55_2X)

```
ping www.google.com
```

```
exit
```

```
docker ps -a
```

```
docker run -it busybox:1 echo "hello world"
```

![](/files/-MOY2zNjlzTE06BkNh64)

```
docker pull gcc
```

![](/files/-MOY4cRiRdlNNAawGWtw)

```
docker run -it -v /data:/data gcc:latest bash
```

```
cd /data
```

```
cat hello.c
```

![](/files/-MOY8IO41qvLM7FaQR9Z)

```
gcc -o hello hello.c
```

```
exit
```

![](/files/-MOY9udvaDurNH9ajPOD)

```
docker pull codenvy/python27
```

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

{% tab title="PuTTY" %}

```
mkdir -p /data
```

```
cd /data
```

```
vim hello.c
```

![](/files/-MOY5VsZ7dtZbzmVY53V)

```
#include <stdlib.h>
#include <stdio.h>

int main(){
    printf("hello world\n");
    return 0;
}
```

![](/files/-MOY6otNdWFqHg2_Xz-_)

```
./hello
```

![](/files/-MOY9bPQ05s06ehx7pKq)

```
vim p2.py
```

```
[Service]

print "hello world"
```

![](/files/-MOYCCNxxQzLv6eHcpED)

```
vim p3.py
```

```
print ("hello world")
```

```
cat p2.py
```

```
cat p3.py
```

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

> #### 一次就可以刪除已經不在執行的容器

```
docker rm -f `docker ps -a -q`
```

{% hint style="danger" %}
`docker rmi`要確保沒有任何相關容器正在運行
{% endhint %}

### Part 02.

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

```
cd /data
```

```
mkdir -p /myweb
```

```
cd /myweb
```

```
echo "hello world" > index.html
```

```
docker run -itd --name myweb1 -p 8080:80 httpd
```

![](/files/-MOYFRZ8EndFEjuAJ62i)

![](/files/-MOYFzvT2TDDUECEaVXV)

```
docker run -itd --name myweb2 -v /myweb: docker run -it --rm busybox:latest echo "hello" -p 8080:80 httpd
```

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

![](/files/-MOYHQrJuDWlZxGO5QfI)

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

![](/files/-MOYISj77huerv-sNHRS)

```
docker exec -it myweb3 bash
```

```
cd htdoc
```

```
cat index.html
```

```
exit
```

![](/files/-MOYIx0hAoqZJQXy9kGn)

```
docker rm -f myweb3
```

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

![](/files/-MOYNyqT1tLoUuRiAgO7)

### Part 03.

```
docker run -itd --name myweb4 -p 8082:80 httpd
```

```
cd /myweb
```

```
docker cp index.html myweb4:/usr/local/apache2/htdocs
```

![](/files/-MO_-zhUEKkJu4oDVt5b)

![](/files/-MO_0BbmlWWyF-epzO7X)

```
docker commit [容器ID] [xiaoji850312/鏡像名稱]:v1
```

![](/files/-MO_3HtU1Pp5xUqy4fHs)

```
docker run -itd --name myweb5 -p 8083:80 xiaoji850312/myweb4:v1
```

![](/files/-MO_4hpo4i5dUGoCRgq6)

![](/files/-MO_4bScfrhuzcWsUY0f)

```
docker ps
```

```
docker attach [容器ID]
```
