Docker---鏡像操作


前言

前面已經介紹了如何安裝docker和配置docker的阿里雲鏡像地址,那么這里安靜簡單的介紹下一些鏡像的簡單操作

啟動鏡像

安靜安裝完成Docker后,並沒有在上面安裝其他的鏡像文件,然后直接通過 Docker run 鏡像名 進行啟動鏡像。

 這里通過上圖可以看到,docker查看本地有沒有鏡像,如果沒有的話就去docker hub上進行查找,如果存在這個鏡像,就進行下載下來。安靜在隨便啟動一個鏡像,就會報錯了,表示找不到這個鏡像文件

其他操作

可以通過 docker run --help 進行查看docker啟動容器鏡詳細命令,這里安靜簡單的介紹下我們常用到的幾個參數

# 啟動docker
docker run [OPTIONS] IMAGE [COMMAND][ARG...]
# 常用參數說明
--name="Name"     # 給容器指定一個名字
-d     # 后台方式運行容器,並返回容器的id!
-i     # 以交互模式運行容器,通過和 -t 一起使用
-t     # 給容器重新分配一個終端,通常和 -i 一起使用
-P     # 隨機端口映射(大寫)
-p     # 指定端口映射(小結),一般可以有四種寫法

查看本地鏡像

如果不知道本地有什么鏡像,我們可以通過 docker images  進行查看,顯示的是我們本地所有的鏡像文件

[root@anjing anjing]# docker images 
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   2 months ago   13.3kB

REPOSITORY     # 表示鏡像名稱
TAG                  # 表示鏡像的版本標簽
IMAGE ID          # 表示鏡像的ID
CREATED           # 表示鏡像的創建時間
SIZE                 # 表示鏡像的大小

其他參數

-a :表示查看本地所有鏡像

-q:表示只顯示鏡像ID

幫助文檔

如果不知道具體使用方法,我們可以通過 docker images --help 進行查看

[root@anjing ~]# docker images  --help

Usage:  docker images [OPTIONS] [REPOSITORY[:TAG]]

List images

Options:
  -a, --all             Show all images (default hides intermediate images)
      --digests         Show digests
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print images using a Go template
      --no-trunc        Don't truncate output
  -q, --quiet           Only show image IDs
[root@anjing ~]# 

查找鏡像

當我們想要搜索鏡像看看是否存在的時候,我們可以通過 docker search 鏡像名 進行查看docker hub上是否存在。存在就返回對應的信息,如果不存在就返回為空

# 查找存在的鏡像名
[root@anjing ~]# docker search jenkins
NAME                                    DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
jenkins                                 DEPRECATED; use "jenkins/jenkins:lts" instead   5384      [OK]       
jenkins/jenkins                         The leading open source automation server       2793                 
jenkinsci/blueocean                     https://jenkins.io/projects/blueocean           657                  

# 查找不存在的鏡像名
[root@anjing ~]# docker search anjing666
NAME      DESCRIPTION   STARS     OFFICIAL   AUTOMATED

幫助文檔

如果不清楚具體使用方法,我們通過 docker search --help 看具體幫助文檔

[root@anjing ~]# docker search --help

Usage:  docker search [OPTIONS] TERM

Search the Docker Hub for images

Options:
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print search using a Go template
      --limit int       Max number of search results (default 25)
      --no-trunc        Don't truncate output

下載鏡像

通過上面命令搜索到了想要下載的鏡像,就可以通過 docker pull 鏡像名  進行下載鏡像。這里默認下載時最新版本。

[root@anjing ~]# docker pull jenkins
Using default tag: latest
latest: Pulling from library/jenkins
55cbf04beb70: Pull complete 
1607093a898c: Pull complete 
9a8ea045c926: Pull complete 
d4eee24d4dac: Pull complete 
c58988e753d7: Pull complete 
794a04897db9: Pull complete 
70fcfa476f73: Pull complete 
0539c80a02be: Pull complete 
54fefc6dcf80: Pull complete 
911bc90e47a8: Pull complete 
38430d93efed: Pull complete 
7e46ccda148a: Pull complete 
c0cbcb5ac747: Pull complete 
35ade7a86a8e: Pull complete 
aa433a6a56b1: Pull complete 
841c1dd38d62: Pull complete 
b865dcb08714: Pull complete 
5a3779030005: Pull complete 
12b47c68955c: Pull complete 
1322ea3e7bfd: Pull complete 
Digest: sha256:eeb4850eb65f2d92500e421b430ed1ec58a7ac909e91f518926e02473904f668
Status: Downloaded newer image for jenkins:latest
docker.io/library/jenkins:latest

指定版本下載

我們想要指定版本下載,首先要去docker hub上查看對應鏡像是否存在當前版本。Docker hub倉庫(https://hub.docker.com/)

 

 

在進行安裝的時候執行對應的版本號 docker pull xxxx:xxx 

[root@anjing ~]# docker pull jenkins:2.60.3
2.60.3: Pulling from library/jenkins
Digest: sha256:eeb4850eb65f2d92500e421b430ed1ec58a7ac909e91f518926e02473904f668
Status: Downloaded newer image for jenkins:2.60.3
docker.io/library/jenkins:2.60.3

通過查看本地存在哪些docker可以看出來有2個不同的jenkins版本

[root@anjing ~]# docker images -a 
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   2 months ago   13.3kB
jenkins       2.60.3    cd14cecfdb3a   3 years ago    696MB
jenkins       latest    cd14cecfdb3a   3 years ago    696MB

幫助文檔

同樣我們可以通過 docker pull --help  進行查看對應的幫助文檔

[root@anjing ~]# docker pull --help 

Usage:  docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Pull an image or a repository from a registry

Options:
  -a, --all-tags                Download all tagged images in the repository
      --disable-content-trust   Skip image verification (default true)
      --platform string         Set platform if server is multi-platform capable
  -q, --quiet                   Suppress verbose output

刪除鏡像

如果想要刪除鏡像的話,可以通過 docker rmi  進行刪除鏡像

[root@anjing ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   2 months ago   13.3kB
jenkins       2.60.3    cd14cecfdb3a   3 years ago    696MB
jenkins       latest    cd14cecfdb3a   3 years ago    696MB

[root@anjing ~]# docker rmi -f feb5d9fea6a5
Untagged: hello-world:latest
Untagged: hello-world@sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412

[root@anjing ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
jenkins      2.60.3    cd14cecfdb3a   3 years ago   696MB
jenkins      latest    cd14cecfdb3a   3 years ago   696MB

通過執行上述命令發現我們已經成功的將鏡像進行了刪除

其他用法

如果想要刪除更多或者全部的話我們可以也可以通過 docker rmi  后面跟上不同的參數

刪除單個:docker rmi -f 鏡像id

刪除多個:docker rmi -f 鏡像名:tag  鏡像名:tag

刪除全部:docker rmi -f(docker images -qa)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM