Doker的基础命令:

docker

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
[root@localhost ~]# docker

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:      --config string      Location of client config files (default "/root/.docker")  -D, --debug              Enable debug mode  -H, --host list          Daemon socket(s) to connect to  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")      --tls                Use TLS; implied by --tlsverify      --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")      --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")      --tlsverify          Use TLS and verify the remote  -v, --version            Print version information and quit

Management Commands:     #管理命令  builder     Manage builds  config      Manage Docker configs  #管理配置  container   Manage containers      #管理容器   engine      Manage the docker engine   # 管理引擎  image       Manage images               #管理插件  network     Manage networks  node        Manage Swarm nodes            #管理节点  plugin      Manage plugins  secret      Manage Docker secrets  service     Manage services  stack       Manage Docker stacks  swarm       Manage Swarm  system      Manage Docker  trust       Manage trust on Docker images  volume      Manage volumes

## docker 兼容了新旧的使用格式 建议使用分组管理.

Commands:  attach      Attach local standard input, output, and error streams to a running container  build       Build an image from a Dockerfile  commit      Create a new image from a container's changes  cp          Copy files/folders between a container and the local filesystem  create      Create a new container  diff        Inspect changes to files or directories on a container's filesystem  events      Get real time events from the server  exec        Run a command in a running container  export      Export a container's filesystem as a tar archive  history     Show the history of an image  images      List images  import      Import the contents from a tarball to create a filesystem image  info        Display system-wide information  inspect     Return low-level information on Docker objects  kill        Kill one or more running containers  load        Load an image from a tar archive or STDIN  login       Log in to a Docker registry  logout      Log out from a Docker registry  logs        Fetch the logs of a container  pause       Pause all processes within one or more containers  port        List port mappings or a specific mapping for the container  ps          List containers  pull        Pull an image or a repository from a registry  push        Push an image or a repository to a registry  rename      Rename a container  restart     Restart one or more containers  rm          Remove one or more containers  rmi         Remove one or more images  run         Run a command in a new container  save        Save one or more images to a tar archive (streamed to STDOUT by default)  search      Search the Docker Hub for images  start       Start one or more stopped containers  stats       Display a live stream of container(s) resource usage statistics  stop        Stop one or more running containers  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE  top         Display the running processes of a container  unpause     Unpause all processes within one or more containers  update      Update configuration of one or more containers  version     Show the Docker version information  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

查看版本

1234567891011121314151617181920
[root@localhost ~]# docker versionClient:              #客户端 Version:           18.09.4    #docker版本 API version:       1.39     #Docker接口版本 Go version:        go1.10.8  # Docker Go版本 Git commit:        d14af54266 Built:             Wed Mar 27 18:34:51 2019 OS/Arch:           linux/amd64  #  系统 Experimental:      false        # 是否为企业版

Server: Docker Engine - Community    Engine:  Version:          18.09.4  API version:      1.39 (minimum version 1.12)  Go version:       go1.10.8  Git commit:       d14af54  Built:            Wed Mar 27 18:04:46 2019  OS/Arch:          linux/amd64  Experimental:     falseYou have new mail in /var/spool/mail/root

详细信息

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
[root@localhost ~]# docker infoContainers: 0   #容器个数 Running: 0    # 运行 Paused: 0    # 暂停 Stopped: 0   # 停止Images: 0      # 镜像Server Version: 18.09.4  #服务器版本Storage Driver: overlay2  #存储驱动后端 很重要  分层构建和联合挂载 需要专门的文件驱动在之前可能是使用的DM 性能奇差 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: trueLogging Driver: json-fileCgroup Driver: cgroupfsPlugins:         #  插件 Volume: local         #卷 Network: bridge host macvlan null overlay  # 网络插件 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog  #日志插件Swarm: inactiveRuntimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30init version: fec3683Security Options:  #安全选项 seccomp       Profile: default  #默认选项Kernel Version: 3.10.0-957.10.1.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 1Total Memory: 3.683GiBName: localhost.localdomainID: BUTI:XQW2:K5UQ:SNVB:EC67:GBOV:LHZD:FI2G:UFL2:TU4H:FSCN:PQAUDocker Root Dir: /var/lib/dockerDebug Mode (client): falseDebug Mode (server): falseRegistry: https://index.docker.io/v1/Labels:Experimental: falseInsecure Registries: 127.0.0.0/8Registry Mirrors: https://registry.docker-cn.com/  #加速镜像配置Live Restore Enabled: falseProduct License: Community Engine

Docker Search

搜索 Docker hub 中的 nginx 镜像

1
docker search nginx

Docker pull

多个层级每一层分别下载

docker images

last表示时最新的

123456
[root@localhost docker]# docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZEnginx               latest              2bcb04bdb83f        9 days ago          109MB[root@localhost docker]# docker image lsREPOSITORY          TAG                 IMAGE ID            CREATED             SIZEnginx               latest              2bcb04bdb83f        9 days ago          109MB

docker 卸载镜像

12345678910111213141516171819
[root@localhost docker]# docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZEbusybox             latest              af2f74c517aa        2 days ago          1.2MBnginx               latest              2bcb04bdb83f        9 days ago          109MB[root@localhost docker]# docker image rm busybox     #第一种命令Untagged: busybox:latest Untagged: busybox@sha256:f79f7a10302c402c052973e3fa42be0344ae6453245669783a9e16da3d56d5b4Deleted: sha256:af2f74c517aac1d26793a6ed05ff45b299a037e1a9eefeae5eacda133e70a825Deleted: sha256:0b97b1c81a3200e9eeb87f17a5d25a50791a16fa08fc41eb94ad15f26516ccea[root@localhost docker]# docker rmi nginx      #第二种命令Untagged: nginx:latestUntagged: nginx@sha256:dabecc7dece2fff98fb00add2f0b525b7cd4a2cacddcc27ea4a15a7922ea47eaDeleted: sha256:2bcb04bdb83f7c5dc30f0edaca1609a716bda1c7d2244d4f5fbbdfef33da366cDeleted: sha256:dfce9ec5eeabad339cf90fce93b20f179926d5819359141e49e0006a52c066caDeleted: sha256:166d13b0f0cb542034a2aef1c034ee2271e1d6aaee4490f749e72d1c04449c5bDeleted: sha256:5dacd731af1b0386ead06c8b1feff9f65d9e0bdfec032d2cd0bc03690698feda[root@localhost docker]# docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZE[root@localhost docker]#

Docker 创建一个容器

12345678910111213141516171819202122232425262728293031323334
[root@localhost docker]# docker container

Usage:  docker container COMMAND

Manage containers

Commands:  attach      Attach local standard input, output, and error streams to a running container  commit      Create a new image from a container's changes  cp          Copy files/folders between a container and the local filesystem  create      Create a new container  diff        Inspect changes to files or directories on a container's filesystem  exec        Run a command in a running container  export      Export a container's filesystem as a tar archive  inspect     Display detailed information on one or more containers  kill        Kill one or more running containers  logs        Fetch the logs of a container  ls          List containers  pause       Pause all processes within one or more containers  port        List port mappings or a specific mapping for the container  prune       Remove all stopped containers  rename      Rename a container  restart     Restart one or more containers  rm          Remove one or more containers  run         Run a command in a new container  start       Start one or more stopped containers  stats       Display a live stream of container(s) resource usage statistics  stop        Stop one or more running containers  top         Display the running processes of a container  unpause     Unpause all processes within one or more containers  update      Update configuration of one or more containers  wait        Block until one or more containers stop, then print their exit codes

Run 'docker container COMMAND --help' for more information on a command.
1234
#启动一个nginx容器[root@localhost ~]# docker run --name nginx-docker1 -d nginx  #-d为后台运行aaed74bf582677ed39f186a3967f4a4efb11836a164b78f1d0b157fb2f26dcaa[root@localhost ~]# docker inspect nginx-docker1             #查看docker绑定地址 为172.17.0.2

Redis

即使本地没有Redis的镜像我们依然可以安装。

1
docker run --name Redis -d redis:4-alpine

进入终端

1
docker exec -it kvsotre /bin/sh     #进入容器中

查看日志

1
docker logs kvstore  #产看kvstore的日志

常用命令

镜像生成途径

基于容器

1.创建一个busybox的容器

1234
[root@localhost ~]# docker run --name b1 -it busybox/ # mkdir -p /data/html/ # vi /data/html/index.html<h1>Busybox httpd Server </h1>
123456789101112
[root@localhost ~]# docker commit  -hFlag shorthand -h has been deprecated, please use --help

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

Create a new image from a container's changes

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) #暂停镜像文件

为了引用方便我们可以给镜像打上标签.

12345
[root@localhost ~]# docker tag --help

Usage:  docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

1234567
docker inspect busybox"Cmd": [                "/bin/sh",                "-c",                "#(nop) ",                "CMD [\"sh\"]"            ],

docker运行镜像生成了原先保存的镜像文件。

123456789101112
[root@localhost ~]# docker commit -hFlag shorthand -h has been deprecated, please use --help

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

Create a new image from a container's changes

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)  # 暂停容器
1
docker commit -a "bigdataxiaohan <467008580@qq.com>" -c 'CMD ["/bin/httpd","-f","-h","/data/html"]' -p t1 hphblog/httpd:v0.2

启动基于v0.2版本的服务

dcoker服务可以直接访问。

由于将docker镜像推导Docker hub 需要相同的组织类名 而我在DockerHub 上创建的仓库为bigdataxiaohan/httpd 我们把镜像更改以下名称

1
docker tag hphblog/httpd:v0.2 bigdataxiaohan/httd:v0.2

然后登录

12345678910
[root@localhost ~]# docker login --help

Usage:  docker login [OPTIONS] [SERVER]

Log in to a Docker registry

Options:  -p, --password string   Password      --password-stdin    Take the password from stdin  -u, --username string   Username

网络不是很好建议多尝试几次。

1
docker tag hphblog/httpd:v0.2 bigdataxiaohan/httpd:v0.2

(⊙﹏⊙) 还是放弃吧 我们可以使用腾讯云的Docker镜像仓库

哎呀妈呀QAQ 终于push成功了

Docker 打包

12345678
[root@localhost ~]# docker  save --help

Usage:  docker save [OPTIONS] IMAGE [IMAGE...]

Save one or more images to a tar archive (streamed to STDOUT by default)

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

Dokcer加载

123456789
[root@localhost ~]# docker load --help

Usage:  docker load [OPTIONS]

Load an image from a tar archive or STDIN

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

1
docker load -i myimages.gz

Docker的基础命令相关推荐

  1. Docker镜像基础命令

    Docker镜像基础命令 给root用户设置密码 Sudo -s à passwd root à su 更新apt的镜像源地址:阿里云 https://opsx.alibaba.com/mirror ...

  2. docker镜像简介和docker常用基础命令

    docker镜像简介和docker常用基础命令 文章目录 docker镜像简介和docker常用基础命令 1:docker镜像概述 1.1:什么是docker镜像 1.2:docker镜像的获取方式 ...

  3. 什么是docker及docker的基础命令

    文章目录 1. 简介 1.1 特性 1.2 组件 1.3 版本 2. 安装部署 2.1 安装说明 2.2 centos7安装 2.3 Debian&Ubuntu 3. 运行docker 3. ...

  4. Docker常用基础命令汇总

    2019独角兽企业重金招聘Python工程师标准>>> 1.docker的启动.停止.重启 [root@localhost ~]# service docker restart Re ...

  5. Docker常用基础命令

    目录 1.docker version  查看版本信息 2.docker info  查看docker的一些信息 3.docker search 镜像搜索 4.docker pull 拉取镜像到本地 ...

  6. Docker学习(2)——图文并茂讲解Docker基础命令

    一.Docker基础命令总结 命令 功能 docker load -i ubuntu.tar 导入镜像 docker run -it --name vm1 ubuntu 创建容器(以ubuntu镜像为 ...

  7. Docker基础命令学习

    Docker基础命令学习 二.Docker 入门 Docker是什么? Docker 是一个开源的应用容器引擎,你可以将其理解为一个轻量级的虚拟机,开发者可以打包他们的应用以及依赖包到一个可移植的容器 ...

  8. Docker学习之二------基础命令(镜像、容器)

    Docker基础命令 配置文件路径: /etc/sysconfig/docker docker镜像及容器目录 docker主目录:/var/lib/docker 存放容器目录:/var/lib/doc ...

  9. 在虚拟机安装中Docker及一些基础命令

    一.安装 yum -y update yum install -y docker docker version 查看docker版本信息 安装成功如上图. 二.基础命令 1.docker pull 镜 ...

最新文章

  1. 面对新型肺炎疫情,AI能做什么?
  2. web developer tips (51):使用vs2005和IE8进行调试
  3. 工作2年,月薪2万,我还是选择了离职
  4. Windows下cmd常用命令【5分钟掌握】
  5. python实现中文字符繁体和简体中文转换
  6. Go map[int64]int64 写入 redis 占用多少内存
  7. 如何以 mock server 的方式本地启动 SAP UI5 应用,使它不连接服务器端 OData 服务
  8. [html] 如何禁止input输入的历史记录
  9. mysql5.5删除干净_MySql5.5 安装及卸载
  10. 网络传输---HttpURLConnection
  11. 转:把二元查找树转变成排序的双向链表
  12. 点击流日志分析项目实战开发流程
  13. 如何快速实现自定义sql分页?若不会,我便手把手教你【详细】
  14. calibre怎么把HTML转换mobi,calibre:mobi格式转换成pdf格式 | 求索阁
  15. ios与Win11文件互传
  16. Mac 安装 MAT内存分析工具
  17. Win7解决telnet不是内部或外部命令的方法
  18. java新特性-函数式接口-作为方法参数-作为方法的返回值-常用函数式接口-Supplier-Consumer-Predicate-Function
  19. 关于自动化安装离线补丁包更新
  20. 电商项目实战第三节: CSS3+HTML5+JS 设计案例【考拉海购网站】之【分类导航栏】

热门文章

  1. linux查看日志文件内容命令tail、cat、tac、head、echo、vi
  2. 读《编程珠玑》 (四)
  3. 实现算法2.11、2.12的程序
  4. zz从一道笔试题谈算法优化(上)
  5. php css去除h1样式,HTML中怎么设置h1的字体样式你知道吗?关于设置h1标签的样式详解...
  6. 数据库-MySQL-JDBC-execute、executeUpdate、executeQuery
  7. 基础知识—数据类型-数据的输出与输入
  8. 2021江津二中高考成绩查询入口,重庆江津第二中学2021年录取分数线
  9. html切换搜索引擎,关于JavaScript如何切换搜索引擎的导航网页搜索框的实例代码分享...
  10. vue路由跳转动画_Vue路由跳转动画