5

Docker基础命令 - Li Hui Blog

 3 years ago
source link: https://lihui.net/docker-base-command.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

image-20210113235714155

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

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

获取镜像(docker pull)

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

$  docker pull {{image_name}}:{{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
$ 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
$ docker rmi centos:latest

image-20210113233530266

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

$ docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Options:
  -a, --author string    Author (e.g., "John Hannibal Smith <[email protected]>")
  -c, --change list      Apply Dockerfile instruction to the created image
  -m, --message string   Commit message
  -p, --pause            Pause container during commit (default true)
$ 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
$ 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
docker load < centos.jar

image-20210113235129588


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK