1.帮助命令
docker verison 版本信息
docker info 具体内容的描述
docker —help 命令没有多少,不够再去看官方文档。
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--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 set
with "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 quit
Management Commands:
app* Docker App (Docker Inc., v0.9.1-beta3)
builder Manage builds
buildx* Build with BuildKit (Docker Inc., v0.5.1-docker)
config Manage Docker configs
container Manage containers
context Manage contexts
image Manage images
manifest Manage Docker image manifests and manifest lists
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run '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 images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-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 SIZE
tomcat latest 040bdb29ab37 5 weeks ago 649MB
hello-world latest bf756fb1ae65 13 months ago 13.3kB
docker images -q //只显示镜像ID
[root@test docker]# docker images -q //只显示镜像ID
040bdb29ab37
bf756fb1ae65
docker images -qa //显示所有镜像的ID
[root@test docker]# docker images -qa //显示所有镜像的ID
040bdb29ab37
bf756fb1ae65
docker images —digests //显示镜像的摘要信息
[root@test docker]# docker images --digests //显示镜像的摘要信息
REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE
hello-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 SIZE
hello-world latest sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b 12 months ago 13.3kB
docker search tomcat 查找镜像
原理是从 hub.docker.com网站中搜的,但是是从阿里云下拉的。
OFFICIAL是官方版的,是自动构建的。
[root@test docker]# docker search tomcat
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat 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 29
consol/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… 10
maluuba/tomcat7-java8 Tomcat7 with java8. 6
rightctrl/tomcat CentOS , Oracle Java, tomcat application ssl… 6 [OK]
arm64v8/tomcat Apache Tomcat is an open source implementati… 3
cfje/tomcat-resource Tomcat Concourse Resource 2
jelastic/tomcat An image of the Tomcat Java application serv… 2
amd64/tomcat Apache Tomcat is an open source implementati… 2
oobsri/tomcat8 Testing CI Jobs with different names. 1
picoded/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… 1
appsvc/tomcat 1
secoresearch/tomcat-varnish Tomcat and Varnish 5.0 0 [OK]
s390x/tomcat Apache Tomcat is an open source implementati… 0
softwareplant/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: latest
latest: Pulling from library/tomcat
6c33745f49b4: Pull complete
ef072fc32a84: Pull complete
c0afb8e68e0b: Pull complete
d599c07d28e6: Pull complete
e8a829023b97: Pull complete //镜像是分层的
d04be46a31d1: Pull complete
db6007c69c35: Pull complete
e4ad4c894bce: Pull complete
248895fda357: Pull complete
277059b4cba2: Pull complete
Digest: sha256:57dae7dfb9b62a413cde65334c8a18893795cac70afc3be589c8336d8244655d
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
docker rmi hello-world 删除单个镜像
[root@test docker]# docker rmi hello-world
Error 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-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
//强制删除后:hello-world已经被删除。
[root@test docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest feba8d001e3f 3 weeks ago 649MB
------------------------------------------------------------------
//找到基于该镜像产生的容器,删除容器再删除镜像就不会报错。
/*
此时的容器已经结束运行,需要找个正在运行的容器,强制删除镜像后看容器还运不运行
经过 centos镜像的实验,强制删除镜像后,容器不会停止运行。
容器可以反复重启进入并输入命令进行操作。
*/
[root@localhost loof]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b87506d81de2 hello-world "/hello" 24 minutes ago Exited (0) 24 minutes ago boring_boyd
742f05c65786 hello-world "/hello" 25 minutes ago Exited (0) 25 minutes ago silly_colden
5a9047fd260d hello-world "/hello" 25 minutes ago Exited (0) 25 minutes ago amazing_pascal
//根据容器id删除过去产生的容器
[root@localhost loof]# docker rm -f $(docker ps -qa)
b87506d81de2
742f05c65786
5a9047fd260d
[root@localhost loof]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest 040bdb29ab37 5 weeks ago 649MB
hello-world latest bf756fb1ae65 13 months ago 13.3kB
//删除容器后删除镜像就不会报错
[root@localhost loof]# docker rmi bf756fb1ae65
Untagged: hello-world:latest
Untagged: hello-world@sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
Deleted: sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63
docker rmi hello-world tomcat 删除多个镜像
docker rmi -f $(docker images -qa) 根据镜像的id来删除