美文网首页
docker(四)docker使用

docker(四)docker使用

作者: 7ColorLotus | 来源:发表于2020-06-05 22:37 被阅读0次
  • 容器的使用
    1. 在docker客户端中,输入docker列出所有的docker命令,并且可以使用docker command --help查看某个command的详细参数
      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
    2. 使用 docker run 命令来在容器内运行一个应用程序
      1)命令:docker run ubuntu:15.10 /bin/echo "Hello world"
      2)各个参数解析:
      docker: Docker 的二进制执行文件。
      run:与前面的 docker 组合来运行一个容器。
      ubuntu:15.10指定要运行的镜像,Docker首先从本地主机上查找镜像是否存在,如果不存在,Docker 就会从镜像仓库 Docker Hub 下载公共镜像。
      /bin/echo "Hello world": 在启动的容器里执行的命令
    3. 进行交互式的容器
      1)命令: docker run -i -t ubuntu:15.10 /bin/bash
      2)各个参数解析:
      -t:在新容器内指定一个伪终端或终端。
      -i:允许你对容器内的标准输入 (STDIN) 进行交互。
    4. 启动容器(后台模式)
      1)命令:docker run -d ubuntu:15.10 /bin/sh -c "while true; do echo hello world; sleep 1; done"
      2)查看当前运行的容器:docker ps
      1>结果解释:
      CONTAINER ID:容器ID
      NAMES:自动分配的容器名称(可修改)
      3)查看容器内的标准日志输出命令:docker logs 2b1b7a428627(容器ID)或者docker logs loving_swanson(容器名称)
    5. 停止容器
      1)使用容器ID:docker stop 容器ID
      2)使用容器名称:docker stop 容器名称
    6. 容器使用命令示例
      1)docker pull training/webapp # 载入镜像
      2)docker run -d -P training/webapp python app.py
      1>-d:让容器在后台运行。
      2>-P:将容器内部使用的网络端口映射到我们使用的主机上。
      3)网络端口的快捷方式
      1>docker port bf08b7f2cd89
      2>docker port wizardly_chandrasekhar
      4)查看应用日志
      1>docker logs -f bf08b7f2cd89 类似linux中的tail -f
      5)查看web应用程序容器的进程
      1>docker top wizardly_chandrasekhar
      6)检查web应用程序
      1> docker inspect wizardly_chandrasekhar
      2>使用 docker inspect 来查看 Docker 的底层信息。它会返回一个 JSON 文件记录着 Docker 容器的配置和状态信息。
      7)停止应用程序
      1>docker stop wizardly_chandrasekhar
      8)重启web应用容器
      1>docker start wizardly_chandrasekhar
      9)移除web应用容器
      1>docker remove wizardly_chandrasekhar
      2>删除容器时,容器必须是停止状态
  • 镜像的使用
    1. 列出镜像列表
      1>列出所有镜像:docker images
      2>查找镜像:docker images|grep imagesname
      3>各选项说明

       REPOSITORY:表示镜像的仓库源
       TAG:镜像的标签
       IMAGE ID:镜像ID
       CREATED:镜像创建时间
       SIZE:镜像大小
      

      4>使用镜像运行容器:docker run -t -i ubuntu:15.10 /bin/bash

    2. 获取一个新的镜像
      1>docker pull ubuntu:13.10

    3. 查找镜像
      1>docker search httpd
      2>说明:
      a,NAME:镜像仓库源的名称
      b,DESCRIPTION:镜像的描述
      c,OFFICIAL:是否docker官方发布
      3>查找到就可以拉取镜像 docker pull httpd
      4>下载完以后就可以是用镜像了, docker run httpd

    4. 更新镜像
      1)使用镜像创建一个容器:docker run -t -i ubuntu:15.10 /bin/bash
      2)使用命令apt-get update进行更新,更新完后退出,root@xxx中的xxx是新的容器ID
      3)docker commit -m="has update" -a="lotus" 1293b8915b27 lotus/ubuntu:v2

         -m:提交的描述信息
         -a:指定镜像作者
         1293b8915b27:容器ID
         lotus/ubuntu:v2 :指定要创建的目标镜像名
      
    5. 当出现异常:Error response from daemon: client is newer than server (client API version: 1.24, server API version: 1.22)
      解决方案:export DOCKER_API_VERSION=1.19(版本保持跟服务端一致或更低)

相关文章

网友评论

      本文标题:docker(四)docker使用

      本文链接:https://www.haomeiwen.com/subject/rrbzzhtx.html