docker学习3-镜像的基本使用

查看镜像列表

使用docker images查看本地已经下载的镜像

  • REPOSITORY:表示镜像的仓库源
  • TAG:镜像的标签,区分不同版本
  • IMAGE ID:镜像ID,16进制组成,唯一标识
  • CREATED:镜像创建时间
  • SIZE:镜像大小

[root@bogon ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos/python-36-centos7 latest b8d15efaa8ec 5 months ago 651MB
training/webapp latest 6fae60ef3446 4 years ago 349MB
[root@bogon ~]#

我们本地下载的镜像文件是从仓库下载过来的,每个镜像在仓库源都有个名称,也就是 REPOSITORY,同一个镜像源可以有不同的版本,同标签(TAG)区分

下载镜像

直接使用 docker pull centos 默认是下载的最新的latest版本

docker pull centos

[root@bogon ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
d8d02d457314: Pull complete 
Digest: sha256:307835c385f656ec2e2fec602cf093224173c51119bbebd602c53c3653a3d6eb
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
[root@bogon ~]# docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
centos                     latest              67fa590cfc1c        13 days ago         202MB
centos/python-36-centos7   latest              b8d15efaa8ec        5 months ago        651MB
training/webapp            latest              6fae60ef3446        4 years ago         349MB
[root@bogon ~]# 

  

搜索镜像

docker search搜索相关的镜像文件

Search the Docker Hub for images
[root@bogon ~]# docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 5535 [OK]
ansible/centos7-ansible Ansible on Centos7 122 [OK]
jdeathe/centos-ssh CentOS-6 6.10 x86_64 / CentOS-7 7.6.1810 x86… 111 [OK]
consol/centos-xfce-vnc Centos container with "headless" VNC session… 99 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 62
imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 57 [OK]
tutum/centos Simple CentOS docker image with SSH access 45
centos/postgresql-96-centos7 PostgreSQL is an advanced Object-Relational … 39
kinogmt/centos-ssh CentOS with SSH

果我想下载一个centos7.5的镜像版本,该如何找到呢?

查找TAG版本

如果要找到指定的TAG版本,需打开docker官网https://hub.docker.com/search/?type=image,搜索框输入:centos搜索。
点击详情,找到TAGS,就可以看到不同的标签版本了

接下来指定TAG名称下载,后面加个冒号:标签名称

docker pull centos:centos7.5.1804

更新镜像

上面下载的TAG名称是centos7.5.1804,这个太长了不太好记,可以改成一个自己喜欢的TAG名称,比如7.5

更新镜像需先启动容器

docker run -d centos:centos

  

 [root@bogon ~]# docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b5b7128dfc3d centos "/bin/bash" 8 seconds ago Exited (0) 7 seconds ago youthful_blackwell
a4473d7b0f6d training/webapp "python app.py" About an hour ago Up 24 minutes 0.0.0.0:5000->5000/tcp exciting_vaughan
[root@bogon ~]#

启动之后,查看到容器id号b5b7128dfc3d ,根据容器id,去修改

  • -m:提交的描述信息
  • -a:指定镜像作者
  • e218edb10161:容器ID
  • runoob/ubuntu:v2:指定要创建的目标镜像名

docker commit -m="update tag name" -a="yoyo" b5b7128dfc3d centos:7.5

[root@bogon ~]# docker commit -m="update tag name" -a="leslie" b5b7128dfc3d  centos:7.5
sha256:a7b3006aa7118586800936d9a4c08b34fbd3a7b443b1649cd541f7cbe59469e2
[root@bogon ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS                    NAMES
b5b7128dfc3d        centos              "/bin/bash"         4 minutes ago       Exited (0) 4 minutes ago                            youthful_blackwell
a4473d7b0f6d        training/webapp     "python app.py"     About an hour ago   Up 28 minutes              0.0.0.0:5000->5000/tcp   exciting_vaughan

  

设置镜像TAG

如果只是修改镜像TAG名称,可以用docker tag给镜像取个新的tag名称, 这里的id是镜像的id

docker tag 254d4dfe9df7 centos:v7.5

 

[root@bogon ~]# docker tag a7b3006aa711 centos:v7.5
[root@bogon ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7.5 a7b3006aa711 2 hours ago 202MB
centos v7.5 a7b3006aa711 2 hours ago 202MB
centos/python-36-centos7 latest b8d15efaa8ec 5 months ago 651MB
training/webapp

这时候会多了一个v7.5的标签

删除镜像

上面多了个7.5的TAG,并且IMAGE ID是重复的,可以使用docker rmi 删掉它,可以加-f参数强制删除

  • -f :强制删除;
  • --no-prune :不移除该镜像的过程镜像,默认移除;

[root@bogon ~]# docker rmi centos:v7.5
Untagged: centos:v7.5
[root@bogon ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7.5 a7b3006aa711 2 hours ago 202MB
centos/python-36-centos7 latest b8d15efaa8ec 5 months ago 651MB
training/webapp latest 6fae60ef3446 4 years ago 349MB
[root@bogon ~]#

 

转载于:https://www.cnblogs.com/leslie003/p/11452756.html

Docker是一种开源的容器化平台,通过使用容器来实现应用程序的快速部署和可移植性。以下是一些Docker基本命令: 1. docker run:通过镜像创建并运行一个容器。 2. docker ps:列出当前正在运行的容器。 3. docker stop:停止一个正在运行的容器。 4. docker rm:删除一个已停止的容器。 5. docker images:列出所有的镜像。 6. docker pull:从远程仓库中下载一个镜像。 7. docker push:将一个本地镜像推送到远程仓库。 8. docker build:使用Dockerfile构建一个镜像。 9. docker exec:在一个正在运行的容器中执行命令。 10. docker logs:显示一个容器的日志。 而docker-compose是一个用于定义和运行多个Docker容器的工具。以下是一些docker-compose的基本命令: 1. docker-compose up:根据docker-compose.yml文件启动所有的容器。 2. docker-compose down:停止并删除所有的容器、网络和卷。 3. docker-compose start [服务名称]:启动docker-compose.yml文件中的单个服务。 4. docker-compose stop [服务名称]:停止docker-compose.yml文件中的单个服务。 5. docker-compose restart [服务名称]:重启docker-compose.yml文件中的单个服务。 6. docker-compose logs [服务名称]:显示docker-compose.yml文件中单个服务的日志。 希望以上信息能够对您有所帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [dockerdocker-compose命令学习](https://blog.csdn.net/qq_29277155/article/details/124409801)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值