---
description: docker
---

# 20190313

{% embed url="http://www.weithenn.org/2018/08/docker1806-on-centos75.html" %}



```
# yum install -y docker
```

如果想安裝最新版本

```
# yum curl -sSL https://get.doecker.com | sh
```

```
# systemctl status docker
# systemctl start docker
```

查詢docker的資訊

```
# docker info
```

![](https://1005948644-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LZgzp55XQBZ7U2SrFtZ%2F-L_p_8qjc_COkdM4A3A-%2F-L_pc9FJXw0uEcbVOdmU%2Fimage.png?alt=media\&token=9d154f11-8f85-46af-a5e6-0dab2564f987)

下載images

```
# docker pull centos
```

![](https://1005948644-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LZgzp55XQBZ7U2SrFtZ%2F-L_p_8qjc_COkdM4A3A-%2F-L_pcflNkCrnBghjp025%2Fimage.png?alt=media\&token=b5880a27-2a19-43f4-aa78-8bb9537b3071)

產生容器

```
docker run [選項] 容器名稱 指令 [指令的選項]
```

```
# docker run -it centos:7 /bin/bash
```

![](https://1005948644-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LZgzp55XQBZ7U2SrFtZ%2F-L_p_8qjc_COkdM4A3A-%2F-L_pd9-4LiWVnt2-s9vr%2Fimage.png?alt=media\&token=41d3ac8a-c167-4207-a7f5-bd958f47f8f1)

可以看到root@後面寫著一堆亂碼，代表成功

可以在開另一台終端機確認容器清單

```
# docker ps
```

![](https://1005948644-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LZgzp55XQBZ7U2SrFtZ%2F-L_p_8qjc_COkdM4A3A-%2F-L_pdWNgeoekUnVi8Zu2%2Fimage.png?alt=media\&token=5baf8307-35f1-4dc0-b5b0-7b4f9a9c5a86)

代表我們正在91e0bcef32e1的容器內

接下來可以在容器內測試

![/ifconfig 找不到，ping 可以對外，ls可以使用。](https://1005948644-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LZgzp55XQBZ7U2SrFtZ%2F-L_p_8qjc_COkdM4A3A-%2F-L_pfXyVns1a9zwSsr0e%2Fimage.png?alt=media\&token=a5c68291-94c1-4f41-9199-78c914faf8f8)

在容器內寫一個檔案1.txt，內容是hi\
寫完離開並重新進入

![](https://1005948644-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LZgzp55XQBZ7U2SrFtZ%2F-L_p_8qjc_COkdM4A3A-%2F-L_pgxVTa51Mqu2n5EsG%2Fimage.png?alt=media\&token=0f33a453-c4fd-43eb-9df7-b4e9b6cbe16d)

證實容器可讀不可寫。
