Docker 镜像使用

Docker 镜像操作

1.1 查看镜像

[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
mysql        latest    667ee8fb158e   3 days ago     521MB
centos       latest    5d0da3dc9764   6 months ago   231MB
#REPOSITORY 表示镜像的源
#TAG	    表示镜像的标签:版本号
#IMAGE ID   表示镜像的ID
#CREATED    表示镜像创建的时间
#SIZE       表示镜像的大小

1.2 搜索镜像

[root@localhost ~]# docker search ubuntu
NAME                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
ubuntu                           Ubuntu is a Debian-based Linux operating sys…   13969     [OK]       
websphere-liberty                WebSphere Liberty multi-architecture images …   283       [OK]       
ubuntu-upstart                   DEPRECATED, as is Upstart (find other proces…   112       [OK]       
neurodebian                      NeuroDebian provides neuroscience research s…   88        [OK]       
open-liberty                     Open Liberty multi-architecture images based…   51        [OK]       
ubuntu-debootstrap               DEPRECATED; use "ubuntu" instead                46        [OK]       
ubuntu/nginx                     Nginx, a high-performance reverse proxy & we…   38                   
ubuntu/mysql                     MySQL open source fast, stable, multi-thread…   28                   
ubuntu/apache2                   Apache, a secure & extensible open-source HT…   26                   
ubuntu/prometheus                Prometheus is a systems and service monitori…   23                   
kasmweb/ubuntu-bionic-desktop    Ubuntu productivity desktop for Kasm Workspa…   21                   
ubuntu/squid                     Squid is a caching proxy for the Web. Long-t…   16                   
ubuntu/postgres                  PostgreSQL is an open source object-relation…   15                   
ubuntu/bind9                     BIND 9 is a very flexible, full-featured DNS…   13                   
ubuntu/redis                     Redis, an open source key-value store. Long-…   9                    
ubuntu/grafana                   Grafana, a feature rich metrics dashboard &5                    
ubuntu/prometheus-alertmanager   Alertmanager handles client alerts from Prom…   5                    
ubuntu/memcached                 Memcached, in-memory keyvalue store for smal…   4                    
ubuntu/telegraf                  Telegraf collects, processes, aggregates & w…   3                    
circleci/ubuntu-server           This image is for internal use                  3                    
ubuntu/cortex                    Cortex provides storage for Prometheus. Long…   2                    
ubuntu/cassandra                 Cassandra, an open source NoSQL distributed …   1                    
bitnami/ubuntu-base-buildpack    Ubuntu base compilation image                   0                    [OK]
snyk/ubuntu                      A base ubuntu image for all broker clients t…   0                    

1.3 下载镜像

[root@localhost ~]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
4d32b49e2995: Pull complete 
Digest: sha256:bea6d19168bbfd6af8d77c2cc3c572114eb5d113e6f422573c93cb605a0e2ffb
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest

1.4自己创建一个镜像

[root@localhost ~]# docker run -it -d --name wang centos /bin/bash
478e6f95e377b257d302ae7bdf824f989ecd34cee4018ba3119f38bfbcdbe73a

#我们docker ps 可以看到我们创建好的容器

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
478e6f95e377   centos    "/bin/bash"   16 seconds ago   Up 15 seconds             wang

#然后进入容器

[root@localhost ~]# docker exec -it wang /bin/bash
[root@478e6f95e377 /]# mkdir data
[root@478e6f95e377 /]# ls
bin  data  dev	etc  home  lib	lib64  lost+found  media  mnt  opt  proc  root	run  sbin  srv	sys  tmp  usr  var
[root@478e6f95e377 /]# exit
exit

#我们发现已经创建好了data目录然后退出容器

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
478e6f95e377   centos    "/bin/bash"   3 minutes ago   Up 3 minutes             wang

#这个478e6f95e377 ID就是我们修改过的容器,然后将这个容器重新创建一个镜像

[root@localhost ~]# docker commit wang data:v1
sha256:0443886ccb11a20cbe1181f9a017a95ce128652c29d1a5edc8e055770539fbd3
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
data         v1        0443886ccb11   25 seconds ago   231MB
mysql        latest    667ee8fb158e   3 days ago       521MB
ubuntu       latest    ff0fea8310f3   2 weeks ago      72.8MB
centos       latest    5d0da3dc9764   6 months ago     231MB

#这个data 镜像就是我们刚刚新建的镜像

1.4.1 验证镜像

#我们使用data 镜像启动查看是否有我们新建的目录
[root@localhost ~]# docker run -it -d --name data data:v1 /bin/bash
1801da1a6de65ed33e1f0af0908c9b6e24cf62a23e734de3bcd21c88a8cb4d27
[root@localhost ~]# docker exec data ls
bin
data
dev
etc
home
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
#通过查看我们发现有这个data 目录

命令详解
commit : 将一个容器新建成一个镜像 docker commit [容器名] [镜像名]
exec:在容器内部执行命令 docker exec [容器名] [命令]

1.4.2 新建标签

[root@localhost ~]# docker tag 0443886ccb11 data1:v2
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
data1        v2        0443886ccb11   15 minutes ago   231MB
data         v1        0443886ccb11   15 minutes ago   231MB
mysql        latest    667ee8fb158e   3 days ago       521MB
ubuntu       latest    ff0fea8310f3   2 weeks ago      72.8MB
centos       latest    5d0da3dc9764   6 months ago     231MB

#将data 镜像修改一个标签当版本迭代记录,格式 docker tag [镜像ID] [新的镜像名:标签]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值