搜索镜像
从docker官方镜像仓库搜索镜像
docker search [OPTIONS] TERM
OPTIONS:
--automated :只显示自动创建的镜像,默认值为fasle
--filter,-f :显示过滤后的搜索结果
--limit :显示的最大搜索结果,默认值为25
--no-trunc : 显示完整的镜像描述,默认值为fasle
--stars :列出收藏数不小于指定值的镜像,默认值为0
搜索ubuntu镜像
[root@docker ~]# docker search ubuntu NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating s... 6198 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 90 [OK] ubuntu-upstart Upstart is an event-based replacement for ... 74 [OK] ubuntu-debootstrap debootstrap --variant=minbase --components... 30 [OK] torusware/speedus-ubuntu Always updated official Ubuntu docker imag... 28 [OK] nuagebec/ubuntu Simple always updated Ubuntu docker images... 22 [OK] nickistre/ubuntu-lamp LAMP server on Ubuntu 20 [OK] solita/ubuntu-systemd Ubuntu + systemd 8 [OK] nimmis/ubuntu This is a docker images different LTS vers... 7 [OK] darksheer/ubuntu Base Ubuntu Image -- Updated hourly 3 [OK] vcatechnology/ubuntu A Ubuntu image that is updated daily 1 [OK] webhippie/ubuntu Docker images for ubuntu 1 [OK] jordi/ubuntu Ubuntu Base Image 1 [OK] admiringworm/ubuntu Base ubuntu images based on the official u... 1 [OK] konstruktoid/ubuntu Ubuntu base image 0 [OK] forumi0721ubuntuaarch64/ubuntu-aarch64-dev ubuntu-aarch64-dev 0 [OK] labengine/ubuntu Images base ubuntu 0 [OK] forumi0721ubuntuarmhf/ubuntu-armhf-dev ubuntu-armhf-dev 0 [OK] forumi0721ubuntux64/ubuntu-x64-dev-armbian ubuntu-x64-dev-armbian 0 [OK] forumi0721ubuntux64/ubuntu-x64-dev-android ubuntu-x64-dev-android 0 [OK] teamrock/ubuntu TeamRock's Ubuntu image configured with AW... 0 [OK] smartentry/ubuntu ubuntu with smartentry 0 [OK] datenbetrieb/ubuntu custom flavor of the official ubuntu base ... 0 [OK] lynxtp/ubuntu https://github.com/lynxtp/docker-ubuntu 0 [OK] forumi0721ubuntux64/ubuntu-x64-dev ubuntu-x64-dev 0 [OK]
搜索busybox官方镜像。并且stars数不少于3的镜像
[root@docker ~]# docker search --filter "is-official=true" --filter "stars=3" busybox NAME DESCRIPTION STARS OFFICIAL AUTOMATED busybox Busybox base image. 1044 [OK]
镜像下载
从镜像仓库下载镜像,不指定仓库的地址将默认从Docker Hub官方仓库下载镜像
不指定镜像的tag将下载默认latest镜像
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
从docker官方镜像仓库下载nginx镜像
[root@docker yum.repos.d]# docker pull nginx Using default tag: latest latest: Pulling from library/nginx e6e142a99202: Pull complete 8c317a037432: Pull complete af2ddac66ed0: Pull complete Digest: sha256:72c7191585e9b79cde433c89955547685db00f3a8595a750339549f6acef7702 Status: Downloaded newer image for nginx:latest
从指定的镜像仓库192.168.0.180/pan 下载镜像
[root@docker ~]# docker pull 192.168.0.180/pan/pod Using default tag: latest latest: Pulling from pan/pod 5a865e48f2fd: Pull complete a778b52f148e: Pull complete 8d6f83433b16: Pull complete Digest: sha256:a542e98ed123fbba93b820b896d5f563f003bf07b59d5943b591a10f16ce1211 Status: Downloaded newer image for 192.168.0.180/pan/pod:latest
下载碰到的问题:
如果私有仓库未开启https连接,docker默认使用https连接镜像仓库将导致无法下载镜像,编辑文件/etc/docker/daemon.json将私有仓库添加为可信任仓库,没有该文件可手动创建
vi /etc/docker/daemon.json { "insecure-registries" : ["192.168.0.180"] }
如果docker版本太低,此方法无用,则编辑/etc/sysconfig/docker文件,添加可信任仓库
vi /etc/sysconfig/docker INSECURE_REGISTRY='--insecure-registry 192.168.0.180'
镜像操作
查看本地镜像
[root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest c246cd3dd41d 9 days ago 107MB 192.168.0.180/pan/pod latest be92a7c78132 6 weeks ago 205MB
导出本地镜像
镜像下载到本地后存放在分层文件系统中,实用docker save命令可以将其导入到一个普通文件中
[root@docker ~]# docker save -o /root/nginx-img.tar nginx [root@docker ~]# file /root/nginx-img.tar /root/nginx-img.tar: POSIX tar archive [root@docker ~]# ll -h /root/nginx-img.tar -rw------- 1 root root 107M Jul 2 23:59 /root/nginx-img.tar
导入本地镜像
将导出的镜像文件导入到本地镜像库
[root@docker ~]# docker load --input nginx-img.tar 54522c622682: Loading layer [==================================================>] 58.44MB/58.44MB 1c3fae42c500: Loading layer [==================================================>] 52.7MB/52.7MB 87823f21b793: Loading layer [==================================================>] 3.584kB/3.584kB Loaded image: nginx:latest
上传镜像到私有镜像仓库
- 登录镜像仓库
[root@docker ~]# docker login 192.168.0.180 Username: admin Password: Login Succeeded
- 将镜像打一个新的标记
[root@docker ~]# docker tag c246cd3dd41d 192.168.0.180/pan/test [root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.0.180/pan/test latest c246cd3dd41d 9 days ago 107MB nginx latest c246cd3dd41d 9 days ago 107MB 192.168.0.180/pan/pod latest be92a7c78132 6 weeks ago 205MB
- 上传镜像到192.168.0.180私有镜像仓库
[root@docker ~]# docker push 192.168.0.180/pan/test The push refers to a repository [192.168.0.180/pan/test] 87823f21b793: Pushed 1c3fae42c500: Pushed 54522c622682: Pushed latest: digest: sha256:72c7191585e9b79cde433c89955547685db00f3a8595a750339549f6acef7702 size: 948
关于私有镜像仓库的创建后面文章会介绍。
删除镜像
删除本地镜像库中的镜像
[root@docker ~]# docker rmi nginx Untagged: nginx:latest Untagged: nginx@sha256:72c7191585e9b79cde433c89955547685db00f3a8595a750339549f6acef7702 Deleted: sha256:c246cd3dd41d35f9deda43609cdeaa9aaf04d3658f9c5e38aad25c4ea5efee10 Deleted: sha256:faff6e89a68845db6912629dd8b5647545f9198c5e312327a853508f25398c4d Deleted: sha256:17634c028290a76bf93f15b178f7534cca4a38aede119fa760e319019a7bf9c7 Deleted: sha256:54522c622682789028c72c5ba0b081d42a962b406cbc1eb35f3175c646ebf4dc
如果镜像创建了容器,将无法删除该镜像,删除容器后在删除该镜像
来源:http://www.cnblogs.com/panjunbai/p/7106215.html