獲取docker的鏡像後,就可以運行對應的docker的鏡像信息了,運行的命令為run,具體指令總結如下:
-it:開啟交互式的命令
--rm:容器退出時刪除容器的記錄信息
--name:指定容器的名稱
-d:後臺方式運行容器
每個鏡像運行後,都會在容器中存在一條記錄的信息,查詢的指令為:
docker ps -a
下面演示主要運行centos:7.8.2003的鏡像信息,來演示它的過程:
[root@wuyaShare ~]# docker run -it --name centos7.8.2003 centos:7.8.2003
[root@3db6f936ed4b /]# date
Fri Oct 15 09:14:17 UTC 2021
執行後,可以再查看容器中的記錄信息,具體如下:
[root@wuyaShare ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3db6f936ed4b centos:7.8.2003 "/bin/bash" About a minute ago Exited (0) About a minute ago centos7.8.2003
如上,可以看到容器的名稱為:centos7.8.2003。
如果每次運行鏡像不想在容器中記錄它的信息,那麼就可以帶上--rm,下面具體演示下它的使用:
[root@wuyaShare ~]# docker run -it --rm --name centos7.8.2003 centos:7.8.2003
[root@e096c9fd6281 /]# date
Fri Oct 15 10:42:43 UTC 2021
[root@e096c9fd6281 /]# exit
exit
#查看容器記錄,顯示為空
[root@wuyaShare ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
刪除鏡像可以使用鏡像的ID,名字,摘要等方式來進行刪除。刪除鏡像主要是兩種方式,具體總結如下。
未被執行的鏡像,直接可以根據ID,NAME來進行刪除,下面詳細的演示該過程。下面主要顯示使用name來刪除鏡像。
#獲取鏡像信息
[root@wuyaShare ~]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
#查看獲取的鏡像信息
[root@wuyaShare ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 3 weeks ago 13.3kB
#根據name來刪除鏡像
[root@wuyaShare ~]# docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359
[root@wuyaShare ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
下來顯示ID刪除鏡像的信息:
#獲取鏡像信息
[root@wuyaShare ~]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
#查看獲取的鏡像
[root@wuyaShare ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 3 weeks ago 13.3kB
#根據ID刪除鏡像
[root@wuyaShare ~]# docker rmi feb5d9fea6a5
Untagged: hello-world:latest
Untagged: hello-world@sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359
[root@wuyaShare ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE