Docker(二) 鏡像

簡介

Docker鏡像是什麼?
它是一個只讀的文件,就類似於我們安裝操作系統時候所需要的那個iso光盤鏡像,通過運行這個鏡像來完成各種應用的部署。

這裏的鏡像就是一個能被docker運行起來的一個程序。

查看鏡像資源操作命令

docker image 
Usage:  docker image COMMAND

Manage images

Options:
      --help   Print usage

Commands:
  build       Build an image from a Dockerfile
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Display detailed information on one or more images
  load        Load an image from a tar archive or STDIN
  ls          List images
  prune       Remove unused images
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rm          Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

Run 'docker image COMMAND --help' for more information on a command.

搜索鏡像資源

命令格式:docker search [image_name]
[root@VM_0_4_centos docker]# docker search nginx
INDEX       NAME                                        DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/nginx                             Official build of Nginx.                        12386     [OK]       
docker.io   docker.io/jwilder/nginx-proxy               Automated Nginx reverse proxy for docker c...   1704                 [OK]
docker.io   docker.io/richarvey/nginx-php-fpm           Container running Nginx + PHP-FPM capable ...   749                  [OK]
docker.io   docker.io/linuxserver/nginx                 An Nginx container, brought to you by Linu...   84                   
docker.io   docker.io/bitnami/nginx                     Bitnami nginx Docker Image                      73                   [OK]
docker.io   docker.io/tiangolo/nginx-rtmp               Docker image with Nginx using the nginx-rt...   60                   [

OFFICIAL [OK] 說明是官方提供的鏡像

獲取鏡像

命令格式:docker pull [image_name]

拉取mysql鏡像

[root@VM_0_4_centos docker]# docker pull docker.io/mysql
Using default tag: latest
Trying to pull repository docker.io/library/mysql ... 
latest: Pulling from docker.io/library/mysql
d599a449871e: Pull complete 
f287049d3170: Pull complete 
08947732a1b0: Pull complete 
96f3056887f2: Pull complete 
871f7f65f017: Pull complete 
1dd50c4b99cb: Pull complete 
5bcbdf508448: Pull complete 
a59dcbc3daa2: Pull complete 
13e6809ab808: Pull complete 
2148d51b084d: Pull complete 
93982f7293d7: Pull complete 
e736330a6d9c: Pull complete 
Digest: sha256:c93ba1bafd65888947f5cd8bd45deb7b996885ec2a16c574c530c389335e9169
Status: Downloaded newer image for docker.io/mysql:latest

查看本地鏡像

命令格式:docker image ls 
命令格式:docker image

刪除鏡像資源

命令格式:docker image rm [image_id/image_name:image_version]  
命令格式:docker rmi [image_id/image_name:image_version] 

鏡像重命名

docker tag [old_image]:[old_version] [new_image]:[new_version]
[root@VM_0_4_centos docker]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/mysql     latest              d435eee2caa5        4 weeks ago         456 MB
[root@VM_0_4_centos docker]# docker tag docker.io/mysql:latest my_mysql:1.0
[root@VM_0_4_centos docker]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/mysql     latest              d435eee2caa5        4 weeks ago         456 MB
my_mysql            1.0                 d435eee2caa5        4 weeks ago         456 MB

導出鏡像

將已經下載好的鏡像,導出到本地,以備後用

命令格式:docker save -o [包文件] [鏡像]
命令格式:docker save [鏡像1] ... [鏡像n] > [包文件]
docker save  docker.io/mysql > mysql.tar

導入鏡像

命令格式:docker load < [image.tar_name]
命令格式:docker load --input [image.tar_name]
docker load < mysql.tar
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章