获取镜像
$ docker pull ubuntu:14.04
14.04: Pulling from library/ubuntu
2e6e20c8e2e6: Pull complete
0551a797c01d: Pull complete
512123a864da: Pull complete
Digest: sha256:64483f3496c1373bfd55348e88694d1c4d0c9b660dee6bfef5e12f43b9933b30
Status: Downloaded newer image for ubuntu:14.04
docker.io/library/ubuntu:14.04
查看镜像
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zookeeper latest 36c607e7b14d 11 months ago 278MB
rabbitmq latest 7006a3ccf896 13 months ago 220MB
mysql 5.6 8d06d2d16232 14 months ago 303MB
ubuntu 14.04 13b66b487594 20 months ago 197MB
使用tag命令添加镜像标签
$ docker tag rabbitmq:latest myrabbitmq
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zookeeper latest 36c607e7b14d 11 months ago 278MB
myrabbitmq latest 7006a3ccf896 13 months ago 220MB
rabbitmq latest 7006a3ccf896 13 months ago 220MB
mysql 5.6 8d06d2d16232 14 months ago 303MB
ubuntu 14.04 13b66b487594 20 months ago 197MB
使用inspect查看详细信息
$ docker inspect ubuntu:14.0 //获取镜像的基本信息
$ docker inspect -f {{.Id}} ubuntu:14.04 //获取镜像属性id的值
sha256:13b66b487594a1f2b75396013bc05d29d9f527852d96c5577cc4f187559875d0
使用history查看镜像历史
$ docker history ubuntu:14.04
IMAGE CREATED CREATED BY SIZE COMMENT
13b66b487594 20 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 20 months ago /bin/sh -c mkdir -p /run/systemd && echo 'do… 7B
<missing> 20 months ago /bin/sh -c [ -z "$(apt-get indextargets)" ] 0B
<missing> 20 months ago /bin/sh -c set -xe && echo '
#!/bin/sh' > /… 195kB
<missing> 20 months ago /bin/sh -c #(nop) ADD file:276b5d943a4d284f8… 196M
搜索镜像
$ docker search -f STARS=3 nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 17746 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 182
bitnami/nginx Bitnami nginx Docker Image 143 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 69
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 22 [OK]
rancher/nginx-ingress-controller 11
ibmcom/nginx-ingress-controller Docker Image for IBM Cloud Private-CE (Commu… 4
kasmweb/nginx An Nginx image based off nginx:alpine and in… 3
bitnami/nginx-exporter 3
bitnami/nginx-ldap-auth-daemon
删除镜像
$ docker search -f STARS=3 nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 17746 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 182
bitnami/nginx Bitnami nginx Docker Image 143 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 69
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 22 [OK]
rancher/nginx-ingress-controller 11
ibmcom/nginx-ingress-controller Docker Image for IBM Cloud Private-CE (Commu… 4
kasmweb/nginx An Nginx image based off nginx:alpine and in… 3
bitnami/nginx-exporter 3
bitnami/nginx-ldap-auth-daemon 3
创建镜像
基于已有镜像容器创建 docker commit
首先,运行一个镜像,并在其中进行修改操作,记住容器运行的id:dd6b1a3afc6f 如
$ docker run -it ubuntu:14.04 /bin/bash
root@dd6b1a3afc6f:/# touch test
root@dd6b1a3afc6f:/# exit
exit
其次,使用docker commit 提交生成新的镜像
$ docker commit -m "a new file" -a "jiepi" dd6b1a3afc6f test:0.1
sha256:a478750ee9fb32f7a91f69516a1a8a73e95eec28d0085c4c59b25ef91ced6140
最后,查看镜像,发现已经生成新的镜像
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test 0.1 a478750ee9fb 8 seconds ago 197MB
zookeeper latest 36c607e7b14d 11 months ago 278MB
rabbitmq latest 7006a3ccf896 13 months ago 220MB
mysql 5.6 8d06d2d16232 14 months ago 303MB
ubuntu 14.04 13b66b487594 20 months ago 197MB
基本本地模板导入 docker import
下载一个镜像如centos-6-x86.tar.gz,模板地址如下
http://openvz.org/Download/templates/precreated
-rw-r--r-- 1 root root 98954220 Mar 17 17:02 centos-6-x86.tar.gz
使用下面命令导入镜像到本地
cat centos-6-x86.tar.gz | docker import - centos-6-x86-64(名字自己定义)
存出和载入镜像
存出镜像,如果要导出镜像到本地文件,可以使用docker save,这样就可以把该镜像分享给他人
$ docker save -o ubuntu_14.04.tar ubuntu:14.04
$ ls ubuntu_14.04.tar
ubuntu_14.04.tar
载入镜像,使用 docker load 将导出的tar文件,再导入到本地镜像库,如
$ docker load --input ubuntu_14.04.tar
Loaded image: ubuntu:14.04
$ docker load < ubuntu_14.04.tar
Loaded image: ubuntu:14.04
上传镜像
$ docker push user/test:0.1