我尝试使用Windows10上的Docker For Windows来构建CentOS环境(从安装到容器创建和删除)
首先
本文所讲述的内容
- 筆者がWindows10のデスクトップPCにCentOS環境を構築した際の手順
本文不写的内容
- CentOSの細かい説明
在Windows上,有哪些方法可以搭建CentOS环境?
1. 在Windows上安装虚拟机软件,然后在虚拟机上安装CentOS。
2. 使用WSL(Windows Subsystem for Linux)2来安装CentOS。
3. 安装Docker For Windows,并构建CentOS环境。
本次选择这个选项
使用Docker for Windows安装并搭建CentOS环境。
开始环境搭建
激活Hyper-V

获取 Docker ID

安装Docker Desktop for Windows
从 Docker 的官方网站(https://www.docker.com/products/docker-desktop)下载安装程序。



完成安装后,会提示重新启动,所以请重新启动。
启动Docker桌面版


看来需要应用WSL的更新程序。
请从微软官方网站安装此更新程序。


在CentOS服务器上进行环境搭建。
我正在使用Windows PowerShell执行以下命令。
获取CentOS镜像
Docker镜像是用于创建容器的操作环境模板。
> docker pull centos:centos8
[結果]
centos8: Pulling from library/centos
xxxxxxxxxxx: Pull complete
Digest: sxxxx:xx7fdxxxxx7143cbxxxxxx1c40xxd534bbxxxxxxx7xxxxb1xx
Status: Downloaded newer image for centos:centos8
docker.io/library/centos:centos8
显示图像信息
> docker images
[結果]
REPOSITORY TAG IMAGE ID CREATED SIZE
centos centos8 xxxxxxxxxxxx 12 months ago 231MB

创建容器
Docker容器是使用Docker镜像创建的虚拟化环境。
> docker run -it --name="testos01" centos:centos8 /bin/bash
[結果] ※コンテナが作成されログインした状態になります。
[root@xxxxxxxxxxx /]#
※一旦exitコマンドでログアウトして、コンテナを停止します。
exit
>

您可以使用PS命令确认容器列表中是否已经添加了名为”testos01″的容器。
> docker ps -a
[結果] -a オプションを付けた場合は停止中のコンテナも表示されます。
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
xxxxxxxxxxxx centos:centos8 "/bin/bash" About a minute ago Exited (0) About a minute ago testos01

对于Docker Desktop,您可以在操作按钮下的列表屏幕上进行重启/停止/删除等后续操作。
重新启动容器
我将重新启动先前停止的容器。
docker start testos01
[結果]
testos01
使用ps命令来确认启动情况。
> docker ps
[結果]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
xxxxxxxxxxxx centos:centos8 "/bin/bash" 10 minutes ago Up 5 minutes testos01
无事容器已成功启动。
停止容器
> docker stop testos01
[結果]
testos01
我們將使用ps命令確認是否已停止。
> docker ps -a
[結果] -a オプションを付けた場合は停止中のコンテナも表示されます。
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
xxxxxxxxxxxx centos:centos8 "/bin/bash" 16 minutes ago Exited (0) 40 seconds ago testos01
删除容器
> docker rm testos01
[結果]
testos01
我会使用ps命令确认已经被删除的事项。
> docker ps -a
[結果]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
删除图片
在删除之前确认图像
> docker images
[結果]
REPOSITORY TAG IMAGE ID CREATED SIZE
centos centos8 xxxxxxxxxxxx 12 months ago 231MB
执行删除操作
> docker rmi centos:centos8
[結果]
Untagged: centos:centos8
Untagged: centos@xxxxxx:xx7fd8080b517143cbbbabxxxxxxxxxxxxxxbdee55bd6c473f432b177
Deleted: xxxxxx:5d0da3dc976460b72c7xxxxxxxxxxxxx20b0416bfc16c52c4xxxxxxxxxxfadb6
Deleted: xxxxxx:74ddxxxxxxxxxxxxxba91a0a3053b02xxxxxxxxxxxxxxx89f85xxxx360xx6b59
我要确认一下使用imsges命令是否已经删除了。
> docker images
[結果]
REPOSITORY TAG IMAGE ID CREATED SIZE
以上 —> 以上
下一次,我计划发布关于在容器上操作的帖子。