Docker(二):Docker的基本使用

1 Docker的基本使用

1.1 镜像相关操作

1、从DockerHub搜索镜像

[root@master ~]# docker search centos
# 镜像名字                          描述                                             星标      是否官方(有OK表示为官方镜像)
NAME                               DESCRIPTION                                      STARS     OFFICIAL
centos                             DEPRECATED; The official build of CentOS.        7718      [OK]
kasmweb/centos-7-desktop           CentOS 7 desktop for Kasm Workspaces             43
bitnami/centos-base-buildpack      Centos base compilation image                    0
dokken/centos-7                    CentOS 7 image for kitchen-dokken                8
dokken/centos-8                    CentOS 8 image for kitchen-dokken                6
spack/centos7                      CentOS 7 with Spack preinstalled                 2
dokken/centos-6                    EOL: CentOS 6 image for kitchen-dokken           0
spack/centos6                      CentOS 6 with Spack preinstalled                 1
ustclug/centos                     Official CentOS Image with USTC Mirror           0
dokken/centos-stream-8                                                              5
eclipse/centos_jdk8                CentOS, JDK8, Maven 3, git, curl, nmap, mc, …   5
dokken/centos-stream-9                                                              9
corpusops/centos-bare              https://github.com/corpusops/docker-images/      0
corpusops/centos                   centos corpusops baseimage                       0
spack/centos-stream                                                                 2

解释说明:

  • NAME: 镜像仓库源的名称
  • DESCRIPTION: 镜像的描述
  • OFFICIAL: 是否 docker 官方发布
  • stars: 类似 Github 里面的 star,表示点赞、喜欢的意思。
  • AUTOMATED: 自动构建。
    在选择镜像时尽量选择官方构建的镜像,其他镜像可能会存在安全隐患。

2、下载镜像

docker pull centos
# 不知道tag时,默认拉取最新版本。
# tag 相当于版本号
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

## 解释:
library:代表官方仓库的意思

3、查看镜像

docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
centos       latest    5d0da3dc9764   2 years ago   231MB

参数解释:

  • REPOSITORY:镜像名称
  • TAG:相当于软件版本
  • IMAGE ID:镜像ID,镜像的唯一标识
  • CREATED:镜像构建时间
  • SIZE:镜像大小

4、把镜像做成离线包/解压离线包

# 压缩成离线包
[root@master ~]# docker save -o centos.tar.gz centos
[root@master ~]# ls
anaconda-ks.cfg  centos.tar.gz

# 删除
[root@master ~]# docker rmi centos:latest
Untagged: centos:latest
Untagged: centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Deleted: sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6
Deleted: sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59
# 此时已经没有镜像了
[root@master ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE


# 解压离线包
[root@master ~]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值