Docker教程:常用命令

2018-10-1914:28:07后端程序开发Comments2,226 views字数 680阅读模式

Docker是原生基于Linux的软件,因此它提供了在客户端 - 服务器环境中进行交互和工作的命令。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

在这里,我们列出了一些重要和常用的Docker命令。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

1. 查看Docker版本文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

$ docker version
Shell

它用于查看Docker的客户端和服务器版本。如下图所示。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

2. 从Docker文件构建Docker映像文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

$ docker build -t image-name docker-file-location
Shell

-t:它用于指定使用提供的名称来标记Docker映像。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

3. 运行Docker映像文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

$ docker run -d image-name
Shell

-d:用于创建守护程序进程。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

4. 查看可用的Docker映像文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

$ docker images
Shell

5. 查看最近的运行容器文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

$ docker ps -l
Shell

-l:它用于显示最新的可用容器。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

6. 查看所有正在运行的容器文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

$ docker ps -a
Shell

-a:它用于显示所有可用的容器。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

7. 停止运行容器文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

$ docker stop container_id
Shell

container_id:由Docker分配给容器的Id。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

8. 删除一个映像文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

$ docker rmi image-name
Shell

9. 删除所有映像文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

$ docker rmi $(docker images -q)
Shell

10. 强制删除所有映像文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

$ docker rmi -r $(docker images -q)
Shell

-r:用于强制删除映像。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

11. 删除所有容器文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

$ docker rm $(docker ps -a -q)
Shell

12. 进入Docker容器文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html

$ docker exec -it container-id bash
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/6921.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/bc/6921.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定