Li Hui Blog

Li Hui Blog
在时代的层林尽染中书写时代的年华。效能(2022)
  1. 首页
  2. Linux
  3. Docker
  4. 正文

Docker基础命令

1月 13, 2021 247点热度 2人点赞 0条评论

image-20210113235714155

前言

随着容器化技术的推广,在不久的将来,大多数的公司都将采用容器化技术对现有的业务进行改造,因此容器化是一个大趋势, 在当下, 正值云原生的发展的前期, 掌握容器化技术, 对于云原生的业务的了解也是一种帮助, 本文主要还是整理一下Docker的基本命令, Docker基本命令其实很好找到, 本文只是对自己的掌握的命令的一个总结和对Docker命令的整理, 以防自己以后会忘记.

本文采用的是https://www.docker.com/play-with-docker 提供的 每次提供四个小时的试用期, 完全可以满足使用.

内容

获取镜像(docker pull)

命令

image_name是镜像的名称 后面如果没有tag 则默认拉去最新的镜像,如果有则拉去对应Tag号的镜像

$  docker pull {{image_name}}:{{tag}}

demo

带Tag

$ docker pull centos:7

image-20210113232024768

不带Tag

$ docker pull centos

image-20210113232044202

查看镜像信息

命令&&demo

$ docker images

image-20210113232218482

搜寻镜像

命令

$ docker search [OPTIONS] TERM

参数解释

Options:
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print search using a Go template
      --limit int       Max number of search results (default 25)
      --no-trunc        Don't truncate output

demo

$ docker search nginx

image-20210113233133843

删除镜像

删除一个或者多个镜像 注意删除容器时 docker rm CONTAINER

命令

$ docker rmi [OPTIONS] IMAGE [IMAGE...]

参数

Options:
  -f, --force      Force removal of the image
      --no-prune   Do not delete untagged parents

demo

$ docker rmi centos:latest

image-20210113233530266

创建镜像

从一个变化的容器种创建一个镜像,为何这样说,因为容器是可写的,而镜像也就是image是只读的.

命令

$ docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

参数

Options:
  -a, --author string    Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  -c, --change list      Apply Dockerfile instruction to the created image
  -m, --message string   Commit message
  -p, --pause            Pause container during commit (default true)

demo

$ docker commit -m "Added a demo file" -a "dockerUser" d4b6b8a8db0d demoImg:0.0.1

image-20210113234321827

image-20210113234332658

存入和载入镜像

存入镜像

导出镜像为本地tar文档

命令

$ docker save [OPTIONS] IMAGE [IMAGE...]

参数

Options:
  -o, --output string   Write to a file, instead of STDOUT

demo

$ docker save -o centos.tar centos

image-20210113234736875

载入镜像

将导出的tar文件导入到本地镜像仓库中,会导入镜像和其元数据信息

命令

$ docker load [OPTIONS]

参数

Options:
  -i, --input string   Read from tar archive file, instead of STDIN
  -q, --quiet          Suppress the load output

demo

docker load < centos.jar

image-20210113235129588

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: Docker
最后更新:1月 13, 2021

Li Hui

这个人很懒,什么都没留下

点赞

文章评论

取消回复

Li Hui

这个人很懒,什么都没留下

归档
  • 2022年10月 / 1篇
  • 2022年6月 / 1篇
  • 2022年1月 / 6篇
  • 2021年2月 / 1篇
  • 2021年1月 / 8篇
  • 2020年12月 / 1篇
  • 2020年11月 / 2篇
  • 2020年9月 / 23篇
分类
  • Git系列 / 6篇
  • Linux / 10篇
    • CLI应用 / 2篇
    • Docker / 1篇
  • Shell / 2篇
  • Uncategorized / 1篇
  • 从0到1 / 1篇
  • 博客优化 / 3篇
  • 各系列总章节 / 1篇
  • 周年总结 / 1篇
  • 安全 / 2篇
  • 年度总结 / 1篇
  • 年度计划 / 1篇
  • 感想 / 3篇
  • 技术 / 2篇
    • gocd / 1篇
  • 敏捷开发 / 1篇
  • 未分类 / 6篇
  • 知识 / 1篇
  • 读书 / 3篇

COPYRIGHT © 2021 lihui.net. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

京ICP备2020048539号-3