一、docker常用命令
docker --help
docker info
docker version
https://docs.docker.com/reference/
二、镜像命令
docker images
具体列解释含义:
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
同一个仓库源可以有多个TAG,表示这个仓库源的不同版本,我们使用REPOSITORY:TAG来定义不同的镜像。如果不指定一个镜像的版本标签,例如只使用tomcat,docker将默认使用tomcat:latest镜像
docker images -a
docker images -q
docker images --digests
docker images --no-trunc
示例:
[root@izbp1hcw0fjg64l58525bqz ~]# docker images -q
d1165f221234
[root@izbp1hcw0fjg64l58525bqz ~]# docker images --digests
REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE
hello-world latest sha256:0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38 d1165f221234 5 months ago 13.3kB
[root@izbp1hcw0fjg64l58525bqz ~]# docker images --no-trunc
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726 5 months ago 13.3kB
docker search tomcat
STARS:关注度
docker search --filter=stars=300 tomcat
docker pull tomcat
从Docker Hub上查找关注度大于300的tomcat镜像 NAME #名称 DESCRIPTION #描述 STARS #点赞 OFFICIAL #是否官方 AUTOMATED #是否自动构建
[root@izbp1hcw0fjg64l58525bqz ~]
Using default tag: latest
latest: Pulling from library/redis
33847f680f63: Pull complete
26a746039521: Pull complete
18d87da94363: Pull complete
5e118a708802: Pull complete
ecf0dbe7c357: Pull complete
46f280ba52da: Pull complete
Digest: sha256:cd0c68c5479f2db4b9e2c5fbfdb7a8acb77625322dd5b474578515422d3ddb59
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
docker rmi redis
docker rmi -f redis
docker rmi -f redis tomcat nginx
docker rmi -f $(docker images -q)
三、容器命令
只有下载镜像才能运行容器命令
docker run -i -t --name mycentos
docker run -d mycentos
docker start 容器id
docker restart 容器id
docker kill 容器id
docker stop 容器id
示例:
[root@izbp1hcw0fjg64l58525bqz ~]
[root@9ec4a30b3209 /]
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[root@9ec4a30b3209 /]
[root@izbp1hcw0fjg64l58525bqz ~]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker run -it centos /bin/bash
exit
快捷键:Ctrl + P + Q
示例:
[root@izbp1hcw0fjg64l58525bqz ~]
[root@f6db6f0661af /]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f6db6f0661af centos "/bin/bash" About a minute ago Up About a minute elegant_shtern
[root@izbp1hcw0fjg64l58525bqz ~]
f6db6f0661af
[root@izbp1hcw0fjg64l58525bqz ~]
docker logs rabbitmq
docker logs -f -t --tail=20 redis
docker logs --since="2021-08-10" --tail=10 redis
命令:docker exec -it 容器id bashShell
命令:docker attach 容器id bashShell(/bin/bash)
exec:进入容器后,开启一个新的终端,可以再里面操作;
attach:进入容器正在执行的终端,不会启动新的终端进程;
docker cp 容器id:容器内路径 目的主机路径
|