前言:
当前朋友们对“centosdocker命令”大致比较关怀,兄弟们都想要知道一些“centosdocker命令”的相关内容。那么小编在网摘上汇集了一些对于“centosdocker命令””的相关文章,希望兄弟们能喜欢,同学们快快来了解一下吧!说明:把docker常用命令归纳到Linux基础,是因为我本地docker安装在centos上,平时运行实验镜像的时候都是直接在centos上操作运行。
1、docker版本、状态查看
[root@k8smaster test]# docker -vDocker version 20.10.6, build 370c289[root@k8smaster test]# docker versionClient: Docker Engine - Community Version: 20.10.6 API version: 1.41 Go version: go1.13.15 Git commit: 370c289 Built: Fri Apr 9 22:45:33 2021 OS/Arch: linux/amd64 Context: default Experimental: true............2、镜像(image)操作
从仓库拉取镜像:
// Docker的镜像存储在镜像注册中心(image registry)中,默认是Docker Hub(),在拉取镜像的时候也可以指定其它注册中心。// 拉取镜像,使用docker image pull命令[root@k8smaster test]# docker image pull --helpUsage: docker image pull [OPTIONS] NAME[:TAG|@DIGEST]Pull an image or a repository from a registryOptions: -a, --all-tags Download all tagged images in the repository --disable-content-trust Skip image verification (default true) --platform string Set platform if server is multi-platform capable -q, --quiet Suppress verbose output
查询已有镜像:
[root@k8smaster test]# docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEhello-world latest d1165f221234 2 months ago 13.3kB
删除镜像:
[root@k8smaster test]# docker rmi --helpUsage: docker rmi [OPTIONS] IMAGE [IMAGE...]Remove one or more imagesOptions: -f, --force Force removal of the image --no-prune Do not delete untagged parents[root@k8smaster test]# docker rmi -f hello-worldUntagged: hello-world:latestUntagged: hello-world@sha256:5122f6204b6a3596e048758cabba3c46b1c937a46b5be6225b835d091b90e46cDeleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726[root@k8smaster test]# docker image lsREPOSITORY TAG IMAGE ID CREATED SIZE
删除所有的镜像:
[root@k8smaster test]# docker rmi $(docker images -q)3、容器(container)操作
运行容器:
// -d 后台运行 -it交互模式 -p端口映射 --name命名[root@k8smaster io-cached]# docker run --privileged --name=app -itd feisky/app:io-cached742cd266966a35af9088b842c4f607e767a8578b7feb2d29ccf0154986e56f05
容器运行日志查看(用于验证容器是否已经运行):
[root@k8smaster io-cached]# docker logs appReading data from disk /dev/sda2 with buffer size 33554432Time used: 0.410266 s to read 33554432 bytesTime used: 0.011844 s to read 33554432 bytesTime used: 0.011292 s to read 33554432 bytesTime used: 0.011079 s to read 33554432 bytesTime used: 0.011068 s to read 33554432 bytesTime used: 0.010529 s to read 33554432 bytesTime used: 0.011277 s to read 33554432 bytes
查看运行中的容器:
[root@k8smaster io-cached]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES5017ff0bc9a6 feisky/app:io-direct "/app" 5 minutes ago Up 5 minutes app
暂停、重启、删除容器:
[root@k8smaster io-cached]# docker stop appapp[root@k8smaster io-cached]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES[root@k8smaster io-cached]# docker start appapp[root@k8smaster io-cached]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES742cd266966a feisky/app:io-cached "/app" 3 minutes ago Up 4 seconds app[root@k8smaster io-cached]# docker rm -f appapp[root@k8smaster io-cached]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
停止或删除所有容器:
[root@k8smaster io-cached]# docker stop $(docker ps -qa)[root@k8smaster io-cached]# docker rm -f $(docker ps -aq)[root@k8smaster io-cached]# docker rm -f $(docker stop $(docker ps -q))4、进入交互模式
[root@k8smaster io-cached]# docker exec -it app /bin/bash[root@k8smaster io-cached]# docker exec -it app /bin/sh
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #centosdocker命令