1.帮助命令
docker verison 版本信息
docker info 具体内容的描述
docker —help 命令没有多少,不够再去看官方文档。
Usage: docker [OPTIONS] COMMANDA self-sufficient runtime for containersOptions:--config string Location of client config files (default "/root/.docker")-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context setwith "docker context use")-D, --debug Enable debug mode-H, --host list Daemon socket(s) to connect to-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")--tls Use TLS; implied by --tlsverify--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")--tlskey string Path to TLS key file (default "/root/.docker/key.pem")--tlsverify Use TLS and verify the remote-v, --version Print version information and quitManagement Commands:app* Docker App (Docker Inc., v0.9.1-beta3)builder Manage buildsbuildx* Build with BuildKit (Docker Inc., v0.5.1-docker)config Manage Docker configscontainer Manage containerscontext Manage contextsimage Manage imagesmanifest Manage Docker image manifests and manifest listsnetwork Manage networksnode Manage Swarm nodesplugin Manage pluginssecret Manage Docker secretsservice Manage servicesstack Manage Docker stacksswarm Manage Swarmsystem Manage Dockertrust Manage trust on Docker imagesvolume Manage volumesCommands:attach Attach local standard input, output, and error streams to a running containerbuild Build an image from a Dockerfilecommit Create a new image from a container's changescp Copy files/folders between a container and the local filesystemcreate Create a new containerdiff Inspect changes to files or directories on a container's filesystemevents Get real time events from the serverexec Run a command in a running containerexport Export a container's filesystem as a tar archivehistory Show the history of an imageimages List imagesimport Import the contents from a tarball to create a filesystem imageinfo Display system-wide informationinspect Return low-level information on Docker objectskill Kill one or more running containersload Load an image from a tar archive or STDINlogin Log in to a Docker registrylogout Log out from a Docker registrylogs Fetch the logs of a containerpause Pause all processes within one or more containersport List port mappings or a specific mapping for the containerps List containerspull Pull an image or a repository from a registrypush Push an image or a repository to a registryrename Rename a containerrestart Restart one or more containersrm Remove one or more containersrmi Remove one or more imagesrun Run a command in a new containersave Save one or more images to a tar archive (streamed to STDOUT by default)search Search the Docker Hub for imagesstart Start one or more stopped containersstats Display a live stream of container(s) resource usage statisticsstop Stop one or more running containerstag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGEtop Display the running processes of a containerunpause Unpause all processes within one or more containersupdate Update configuration of one or more containersversion Show the Docker version informationwait Block until one or more containers stop, then print their exit codesRun 'docker COMMAND --help' for more information on a command.To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
2.镜像命令
docker images :列出主机上的镜像
[root@test docker]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEhello-world latest bf756fb1ae65 12 months ago 13.3kB
REPOSITORY:表示镜像的仓库源TAG:镜像的标签
IMAGE ID:镜像ID
CREATED:镜像创建时间
SIZE:镜像大小
同一仓库源可以有多个TAG,代表这个仓库源的不同个版本,我们使用REPOSITORY:TAG来定义不同的镜像。如果你不指定一个镜像的版本标签,例如你只使用ubuntu,docker将默认使用ubuntu:latest 镜像
docker images -a //列出本地所有的镜像
[root@test docker]# docker images -a //列出本地所有的镜像REPOSITORY TAG IMAGE ID CREATED SIZEtomcat latest 040bdb29ab37 5 weeks ago 649MBhello-world latest bf756fb1ae65 13 months ago 13.3kB
docker images -q //只显示镜像ID
[root@test docker]# docker images -q //只显示镜像ID040bdb29ab37bf756fb1ae65
docker images -qa //显示所有镜像的ID
[root@test docker]# docker images -qa //显示所有镜像的ID040bdb29ab37bf756fb1ae65
docker images —digests //显示镜像的摘要信息
[root@test docker]# docker images --digests //显示镜像的摘要信息REPOSITORY TAG DIGEST IMAGE ID CREATED SIZEhello-world latest sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec bf756fb1ae65 12 months ago 13.3kB
docker images —no-trunc //显示完整的镜像信息
[root@test docker]# docker images --no-trunc //显示完整的镜像信息REPOSITORY TAG IMAGE ID CREATED SIZEhello-world latest sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b 12 months ago 13.3kB
docker search tomcat 查找镜像
原理是从 hub.docker.com网站中搜的,但是是从阿里云下拉的。
OFFICIAL是官方版的,是自动构建的。
[root@test docker]# docker search tomcatNAME DESCRIPTION STARS OFFICIAL AUTOMATEDtomcat Apache Tomcat is an open source implementati… 2916 [OK]tomee K]bitnami/tomcat Bitnami Tomcat Docker Image 37 [OK]kubeguide/tomcat-app Tomcat image for Chapter 1 29consol/tomcat-7.0 Tomcat 7.0.57, 8080, "admin/admin" 17 [OK]cloudesire/tomcat Tomcat server, 6/7/8 15 [OK]aallam/tomcat-mysql Debian, Oracle JDK, Tomcat & MySQL 13 [OK]arm32v7/tomcat Apache Tomcat is an open source implementati… 10maluuba/tomcat7-java8 Tomcat7 with java8. 6rightctrl/tomcat CentOS , Oracle Java, tomcat application ssl… 6 [OK]arm64v8/tomcat Apache Tomcat is an open source implementati… 3cfje/tomcat-resource Tomcat Concourse Resource 2jelastic/tomcat An image of the Tomcat Java application serv… 2amd64/tomcat Apache Tomcat is an open source implementati… 2oobsri/tomcat8 Testing CI Jobs with different names. 1picoded/tomcat7 tomcat7 with jre8 and MANAGER_USER / MANAGER… 1 [OK]chenyufeng/tomcat-centos tomcat基于centos6的镜像 1 [OK]camptocamp/tomcat-logback Docker image for tomcat with logback integra… 1 [OK]99taxis/tomcat7 Tomcat7 1 [OK]ppc64le/tomcat Apache Tomcat is an open source implementati… 1appsvc/tomcat 1secoresearch/tomcat-varnish Tomcat and Varnish 5.0 0 [OK]s390x/tomcat Apache Tomcat is an open source implementati… 0softwareplant/tomcat Tomcat images for jira-cloud testing 0 [OK][root@test docker]#
docker pull tomcat 拉取镜像
docker pull tomcat 等于docker pull tomcat:latest 不加标签默认是下载了最新版
Using default tag: latestlatest: Pulling from library/tomcat6c33745f49b4: Pull completeef072fc32a84: Pull completec0afb8e68e0b: Pull completed599c07d28e6: Pull completee8a829023b97: Pull complete //镜像是分层的d04be46a31d1: Pull completedb6007c69c35: Pull completee4ad4c894bce: Pull complete248895fda357: Pull complete277059b4cba2: Pull completeDigest: sha256:57dae7dfb9b62a413cde65334c8a18893795cac70afc3be589c8336d8244655dStatus: Downloaded newer image for tomcat:latestdocker.io/library/tomcat:latest
docker rmi hello-world 删除单个镜像
[root@test docker]# docker rmi hello-worldError response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container 04bb185c0723 is using its referenced image bf756fb1ae65//镜像正在运行,需要强制删除//需要强制删除的原因是有基于该镜像运行的容器,可能已经不运行,也有可能正在运行[root@test docker]# docker rmi -f hello-worldUntagged: hello-world:latestUntagged: hello-world@sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eecDeleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b//强制删除后:hello-world已经被删除。[root@test docker]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEtomcat latest feba8d001e3f 3 weeks ago 649MB------------------------------------------------------------------//找到基于该镜像产生的容器,删除容器再删除镜像就不会报错。/*此时的容器已经结束运行,需要找个正在运行的容器,强制删除镜像后看容器还运不运行经过 centos镜像的实验,强制删除镜像后,容器不会停止运行。容器可以反复重启进入并输入命令进行操作。*/[root@localhost loof]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESb87506d81de2 hello-world "/hello" 24 minutes ago Exited (0) 24 minutes ago boring_boyd742f05c65786 hello-world "/hello" 25 minutes ago Exited (0) 25 minutes ago silly_colden5a9047fd260d hello-world "/hello" 25 minutes ago Exited (0) 25 minutes ago amazing_pascal//根据容器id删除过去产生的容器[root@localhost loof]# docker rm -f $(docker ps -qa)b87506d81de2742f05c657865a9047fd260d[root@localhost loof]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEtomcat latest 040bdb29ab37 5 weeks ago 649MBhello-world latest bf756fb1ae65 13 months ago 13.3kB//删除容器后删除镜像就不会报错[root@localhost loof]# docker rmi bf756fb1ae65Untagged: hello-world:latestUntagged: hello-world@sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391dDeleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6bDeleted: sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63
docker rmi hello-world tomcat 删除多个镜像
docker rmi -f $(docker images -qa) 根据镜像的id来删除
