一、獲取鏡像mysql
docker pull NAME[:TAG] 若是不顯式地指定TAG,則默認會選擇latest標籤,即下載倉庫中最新版本的鏡像。
//獲取最新鏡像
docker pull ubuntu
//獲取指定標籤鏡像
docker pull ubuntu:14.04
//獲取指定倉庫鏡像
docker pull registry.hub.docker.com/ubuntu:latest
docker pull dl.dockerpool.com:5000/ubuntusql
二、查看鏡像docker
//查看本地鏡像
docker images
//重命名本地鏡像
docker tag ubuntu:latest ubuntu:16.04
//獲取鏡像詳細信息,JSON格式
docker inspect 0ef2e08ed3fa
//獲取鏡像詳細信息中某一項信息
docker inspect -f {{".Architecture"}} 0ef2e08ed3fa
docker inspect -f {{".RepoTags"}} 0ef2ubuntu
三、搜索鏡像centos
//搜索指定名稱鏡像
docker search centos
docker search perconal*
//限制搜索結果數量,默認25行
docker search centos --limit 3
//是否截斷描述部分輸出,默認截斷
docker search centos --no-trunc
docker search centos --no-trunc=false
//搜索指定星級以上鏡像
docker search mysql -f stars=10bash
四、刪除鏡像post
docker rmi IMAGE [IMAGE...] 其中IMAGE能夠爲鏡像標籤或者IDspa
#當同一個鏡像擁有多個標籤時,docker rmi命令只是刪除了該鏡像多個標籤中的指定標籤,並不影響鏡像文件自己,但當鏡像只剩下一個標籤時,此時就會完全刪除鏡像。
#當docker rmi命令後面跟的是鏡像ID時,會嘗試刪除全部指向該鏡像的標籤,而後刪除鏡像文件自己,若是該鏡像存在多個標籤,默認沒法刪除,須要加-f進行刪除。
#若是有基於該鏡像建立的容器,則默認沒法刪除鏡像,須要先經過docker rm刪除容器,而後再用docker rmi刪除鏡像,或者使用docker rmi -f強制刪除(不推薦)。3d
[root@CentOS702 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 98d35105a391 12 days ago 192 MB ubuntu latest 0ef2e08ed3fa 4 weeks ago 130 MB ubuntu 14.04 7c09e61e9035 4 weeks ago 188 MB hello-world latest 48b5124b2768 2 months ago 1.84 kB helloworld latest 48b5124b2768 2 months ago 1.84 kB [root@CentOS702 ~]# docker rmi 48b5124b2768 Error response from daemon: conflict: unable to delete 48b5124b2768 (must be forced) - image is referenced in multiple repositories [root@CentOS702 ~]# docker rmi -f 48b5124b2768 Untagged: hello-world:latest Untagged: hello-world@sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7 Untagged: helloworld:latest Deleted: sha256:48b5124b2768d2b917edcb640435044a97967015485e812545546cbed5cf0233 Deleted: sha256:98c944e98de8d35097100ff70a31083ec57704be0991a92c51700465e4544d08 [root@CentOS702 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 98d35105a391 12 days ago 192 MB ubuntu latest 0ef2e08ed3fa 4 weeks ago 130 MB ubuntu 14.04 7c09e61e9035 4 weeks ago 188 MB [root@CentOS702 ~]# docker rmi ubuntu:14.04 Error response from daemon: conflict: unable to remove repository reference "ubuntu:14.04" (must force) - container c7d73bda72fc is using its referenced image 7c09e61e9035 [root@CentOS702 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 00a42ce9d621 centos "cat /etc/redhat-r..." 10 minutes ago Exited (0) 10 minutes ago trusting_wescoff c7d73bda72fc ubuntu:14.04 "cat /etc/issue" 2 hours ago Exited (0) 2 hours ago admiring_davinci 0a277f4e0f09 ubuntu "/bin/bash" 2 hours ago Exited (0) 2 hours ago tender_galileo [root@CentOS702 ~]# docker rm c7d73bda72fc c7d73bda72fc [root@CentOS702 ~]# docker rmi ubuntu:14.04 Untagged: ubuntu:14.04 Untagged: ubuntu@sha256:62a5dce5ceccd7f1cb2672a571ebee52cad1f08eec9b57fe4965fb0968a9602e Deleted: sha256:7c09e61e90350e8f5c0cba2979003bdfe32c2d027b68b4f0cf9063cdd7b4bafd Deleted: sha256:304aecb5e13929f85d3ce2e9d83d0212866c8e55a460c94cf24bd75da1c7c153 Deleted: sha256:f302be18d46a45c0edbbd9b4bc02db764a4b0b8cd9bd0490f33dfaff039a3b62 Deleted: sha256:c523f3173f6028e5329fd401331c375f7b9b9e831d915fafaf358f55e36e3747 Deleted: sha256:94e631422130dc414878fd05efe3d59de44c9d8904696a7c299a83f378a92845 Deleted: sha256:c29b5eadf94a90a2abda13e765d4fad4825fd15621dea1d9a98b60b89b835c2a [root@CentOS702 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 98d35105a391 12 days ago 192 MB ubuntu latest 0ef2e08ed3fa 4 weeks ago 130 MB
[root@CentOS702 ~]# docker tag ubuntu:latest ubuntu:16.04
[root@CentOS702 ~]# docker tag ubuntu:latest ubuntu:16
[root@CentOS702 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 16 0ef2e08ed3fa 4 weeks ago 130 MB
ubuntu 16.04 0ef2e08ed3fa 4 weeks ago 130 MB
ubuntu latest 0ef2e08ed3fa 4 weeks ago 130 MB
[root@CentOS702 ~]# docker rmi ubuntu:16 ubuntu:16.04
Untagged: ubuntu:16
Untagged: ubuntu:16.04
[root@CentOS702 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 98d35105a391 12 days ago 192 MB
ubuntu latest 0ef2e08ed3fa 4 weeks ago 130 MB
五、建立鏡像code
建立鏡像的方式有:基於已有鏡像的容器建立、基於本地模版導入、基於Dockerfile建立
5.一、基於已有鏡像的容器建立:
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
主要選項:
-a, --author=" " //做者信息
-m, --message=" " //提交信息
-p, --pause //提交時暫停容器運行(默認)
[root@CentOS702 ~]# docker run -ti ubuntu /bin/bash root@29acd66b0898:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var root@29acd66b0898:/# touch test root@29acd66b0898:/# exit exit [root@CentOS702 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29acd66b0898 ubuntu "/bin/bash" 53 seconds ago Exited (0) 35 seconds ago musing_bardeen [root@CentOS702 ~]# docker commit -m "Add a new file" -a "james" 29acd66b0898 test sha256:545d60ae0415b0fb11591b37644e05f05afc535afd573891017b47cffdd769b0 [root@CentOS702 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE test latest 545d60ae0415 12 seconds ago 130 MB ubuntu latest 0ef2e08ed3fa 4 weeks ago 130 MB
5.二、基於本地模版導入
推薦使用OpenVZ提供的模版來建立,下載地址:https://openvz.org/Download/template/precreated
待補充!!!
六、導出和導入鏡像
可使用docker save和docker load命令來導出和導入鏡像
[root@CentOS702 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 0ef2e08ed3fa 4 weeks ago 130 MB [root@CentOS702 ~]# docker save -o /data/ubuntu_16.04.tar ubuntu:latest [root@CentOS702 ~]# du -sh /data/ubuntu_16.04.tar 130M /data/ubuntu_16.04.tar [root@CentOS702 ~]# docker rmi ubuntu:latest Untagged: ubuntu:latest Deleted: sha256:0ef2e08ed3fabfc44002ccb846c4f2416a2135affc3ce39538834059606f32dd Deleted: sha256:0d58a35162057295d273c5fb8b7e26124a31588cdadad125f4bce63b638dddb5 Deleted: sha256:cb7f997e049c07cdd872b8354052c808499937645f6164912c4126015df036cc Deleted: sha256:fcb4581c4f016b2e9761f8f69239433e1e123d6f5234ca9c30c33eba698487cc Deleted: sha256:b53cd3273b78f7f9e7059231fe0a7ed52e0f8e3657363eb015c61b2a6942af87 Deleted: sha256:745f5be9952c1a22dd4225ed6c8d7b760fe0d3583efd52f91992463b53f7aea3 [root@CentOS702 ~]# docker load -q -i /data/ubuntu_16.04.tar Loaded image: ubuntu:latest [root@CentOS702 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 0ef2e08ed3fa 4 weeks ago 130 MB [root@CentOS702 ~]# docker rmi ubuntu:latest Untagged: ubuntu:latest Deleted: sha256:0ef2e08ed3fabfc44002ccb846c4f2416a2135affc3ce39538834059606f32dd Deleted: sha256:0d58a35162057295d273c5fb8b7e26124a31588cdadad125f4bce63b638dddb5 Deleted: sha256:cb7f997e049c07cdd872b8354052c808499937645f6164912c4126015df036cc Deleted: sha256:fcb4581c4f016b2e9761f8f69239433e1e123d6f5234ca9c30c33eba698487cc Deleted: sha256:b53cd3273b78f7f9e7059231fe0a7ed52e0f8e3657363eb015c61b2a6942af87 Deleted: sha256:745f5be9952c1a22dd4225ed6c8d7b760fe0d3583efd52f91992463b53f7aea3 [root@CentOS702 ~]# docker load < /data/ubuntu_16.04.tar 745f5be9952c: Loading layer [==================================================>] 135.7 MB/135.7 MB 85782553e37a: Loading layer [==================================================>] 15.87 kB/15.87 kB 29660d0e5bb2: Loading layer [==================================================>] 11.78 kB/11.78 kB 440e02c3dcde: Loading layer [==================================================>] 4.608 kB/4.608 kB 56827159aa8b: Loading layer [==================================================>] 3.072 kB/3.072 kB Loaded image: ubuntu:latest
七、上傳鏡像
docker push NAME[:TAG]
待補充!!!