#1.獲取鏡像
咱們可使用docker pull命令從網絡上下載鏡像,命令格式以下java
docker pull imageName[:TAG]
若是不指定TAG,則默認下載最新的鏡像。 若是出現以下錯誤docker
x509: certificate signed by unknown authority
則須要配置Docker加速器,以下連接
https://www.daocloud.io/mirror#accelerator-doc
#2.查看鏡像apache
docker images
#3.鏡像命別名
使用命令ubuntu
docker tag 鏡像名 別名
![]
#4.搜索鏡像
使用命令tomcat
docker search 鏡像名
#5.刪除鏡像網絡
docker rmi 鏡像名(或者ID)
#6.建立鏡像
建立鏡像的方法有三種:
##6.1 基於已有鏡像的容器建立
實際上基於已有的鏡像,在其基礎上修改一些東西,再生成新的鏡像code
[root@localhost /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/ubuntu latest f49eec89601e 5 weeks ago 129.5 MB [root@localhost /]# docker run -it ubuntu WARNING: IPv4 forwarding is disabled. Networking will not work. root@8dfe0092b0d5:/# touch file1 root@8dfe0092b0d5:/# exit exit [root@localhost /]# docker commit 8dfe0092b0d5 test sha256:ace789a750cc1cc1dbe06bebf3c75a2d34c08dbbe91dacb94ef6ea1d15f38af0 [root@localhost /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE test latest ace789a750cc 8 seconds ago 129.5 MB docker.io/ubuntu latest f49eec89601e 5 weeks ago 129.5 MB [root@localhost /]#
##6.2 基於本地模板導入
##6.3 基於Dockerfile建立
#7.存出和載入鏡像
若是須要存出鏡像到本地磁盤,則使用以下命令圖片
[root@localhost /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE test latest ace789a750cc 8 seconds ago 129.5 MB docker.io/ubuntu latest f49eec89601e 5 weeks ago 129.5 MB [root@localhost /]# docker save test > /usr/java/test.tar [root@localhost /]# cd / [root@localhost /]# ls bin boot certs dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var [root@localhost /]# cd usr/java/ [root@localhost java]# ls apache-tomcat-7.0.75 apache-tomcat-7.0.75.tar.gz jdk1.7 test.tar [root@localhost java]#
若是須要從磁盤中導入鏡像到本地鏡像庫,則使用以下命令get
[root@localhost /]# docker load < /usr/java/test.tar Loaded image: test:latest [root@localhost /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE test latest ace789a750cc 23 minutes ago 129.5 MB docker.io/ubuntu latest f49eec89601e 5 weeks ago 129.5 MB [root@localhost /]#
#7.上傳鏡像
使用docker push命令上傳鏡像到倉庫,默認上傳的倉庫的是DockerHub官方倉庫。
命令格式it
docker push 鏡像名
以下
[root@localhost /]# docker push test Error response from daemon: You cannot push a "root" repository. Please rename your repository to docker.io/<user>/<repo> (ex: docker.io/<user>/test) [root@localhost /]# docker tag test panda30/test [root@localhost /]# docker push panda30/test The push refers to a repository [docker.io/panda30/test] Error: Status 403 trying to push repository panda30/test: "Push failed due to a network error. Please try again. If the problem persists, it may be due to a slow connection." [root@localhost /]# docker push panda30/test The push refers to a repository [docker.io/panda30/test] Put https://index.docker.io/v1/repositories/panda30/test/: x509: certificate signed by unknown authority [root@localhost /]# docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: panda30 Password: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled (Client.Timeout exceeded while awaiting headers) [root@localhost /]#