美文网首页
docker学习笔记(一)

docker学习笔记(一)

作者: zcb炒冰 | 来源:发表于2020-02-25 12:38 被阅读0次

    一、win10系统安装

    1、最新版 Toolbox 下载地址: https://www.docker.com/get-docker
    注册dockerId后下载安装即可,另外需要在控制面板->程序和功能->启用或关闭windows功能 中找到Hyper-y选项打钩

    image.png
    2、安装完成后打开cmd命令控制窗,输入docker --version检查是否安装成功
    C:\WINDOWS\system32>docker --version
    Docker version 19.03.5, build 633a0ea
    C:\WINDOWS\system32>
    

    二、docker常用命令:

    docker 查看docker命令集合

    C:\WINDOWS\system32>docker
    
    Usage:  docker [OPTIONS] COMMAND
    
    A self-sufficient runtime for containers
    
    Options:
          --config string      Location of client config files (default
                               "C:\\Users\\Administrator\\.docker")
      -c, --context string     Name of the context to use to connect to the
                               daemon (overrides DOCKER_HOST env var and
                               default context set with "docker context use")
      -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
                               "C:\\Users\\Administrator\\.docker\\ca.pem")
          --tlscert string     Path to TLS certificate file (default
                               "C:\\Users\\Administrator\\.docker\\cert.pem")
          --tlskey string      Path to TLS key file (default
                               "C:\\Users\\Administrator\\.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
      context     Manage contexts
      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
    
    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.
    

    docker [command] --help 查看命令具体使用

    // 查看search命令的使用方式以及命令参数
    C:\WINDOWS\system32>docker search --help
    
    Usage:  docker search [OPTIONS] TERM
    
    Search the Docker Hub for images
    
    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 从docker仓库中查找镜像

    // 以下是查找tomcat的镜像
    C:\WINDOWS\system32>docker search tomcat
    NAME                          DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
    tomcat                        Apache Tomcat is an open source implementati…   2646                [OK]
    tomee                         Apache TomEE is an all-Apache Java EE certif…   74                  [OK]
    dordoka/tomcat                Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base…   53                                      [OK]
    bitnami/tomcat                Bitnami Tomcat Docker Image                     31                                      [OK]
    kubeguide/tomcat-app          Tomcat image for Chapter 1                      28
    consol/tomcat-7.0             Tomcat 7.0.57, 8080, "admin/admin"              17                                      [OK]
    cloudesire/tomcat             Tomcat server, 6/7/8                            15                                      [OK]
    aallam/tomcat-mysql           Debian, Oracle JDK, Tomcat & MySQL              12                                      [OK]
    arm32v7/tomcat                Apache Tomcat is an open source implementati…   10
    rightctrl/tomcat              CentOS , Oracle Java, tomcat application ssl…   6                                       [OK]
    unidata/tomcat-docker         Security-hardened Tomcat Docker container.      4                                       [OK]
    maluuba/tomcat7-java8         Tomcat7 with java8.                             4
    amd64/tomcat                  Apache Tomcat is an open source implementati…   2
    arm64v8/tomcat                Apache Tomcat is an open source implementati…   2
    i386/tomcat                   Apache Tomcat is an open source implementati…   1
    ppc64le/tomcat                Apache Tomcat is an open source implementati…   1
    camptocamp/tomcat-logback     Docker image for tomcat with logback integra…   1                                       [OK]
    99taxis/tomcat7               Tomcat7                                         1                                       [OK]
    oobsri/tomcat8                Testing CI Jobs with different names.           1
    jelastic/tomcat               An image of the Tomcat Java application serv…   0
    cfje/tomcat-resource          Tomcat Concourse Resource                       0
    secoresearch/tomcat-varnish   Tomcat and Varnish 5.0                          0                                       [OK]
    picoded/tomcat7               tomcat7 with jre8 and MANAGER_USER / MANAGER…   0                                       [OK]
    s390x/tomcat                  Apache Tomcat is an open source implementati…   0
    appsvc/tomcat                                                                 0
    

    docker pull 从docker仓库中拉取镜像

    // 从docker仓库中拉取nginx的最新镜像
    C:\WINDOWS\system32>docker pull nginx:latest
    latest: Pulling from library/nginx
    Digest: sha256:ad5552c786f128e389a0263104ae39f3d3c7895579d45ae716f528185b36bc6f
    Status: Image is up to date for nginx:latest
    docker.io/library/nginx:latest
    

    docker images 查看本地所有镜像列表

    C:\WINDOWS\system32>docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    ubuntu              latest              72300a873c2c        3 days ago          64.2MB
    nginx               latest              2073e0bcb60e        3 weeks ago         127MB
    hello-world         latest              fce289e99eb9        14 months ago       1.84kB
    ubuntu              15.10               9b9cb95443b5        3 years ago         137MB
    

    docker image ls 等同于docker images

    C:\WINDOWS\system32>docker image ls
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    ubuntu              latest              72300a873c2c        3 days ago          64.2MB
    tomcat              latest              aeea3708743f        13 days ago         529MB
    nginx               latest              2073e0bcb60e        3 weeks ago         127MB
    hello-world         latest              fce289e99eb9        14 months ago       1.84kB
    ubuntu              15.10               9b9cb95443b5        3 years ago         137MB
    

    docker --version 检查docker版本号

    C:\WINDOWS\system32>docker --version
    Docker version 19.03.5, build 633a0ea
    

    docker run 运行容器docker ps 查看容器运行状态

    // 运行容器名为nginx-test1的nginx容器,并且使用8080端口和80端口,-d表示后台运行
    C:\WINDOWS\system32>docker run --name nginx-test1 -p 8080:80 -d nginx
    e553b61e8e1d5cb0af5b19ab9abe6f1b2d14bef372afc505390eb9edea3a5103
    // 查看容器状态,以下是刚启动的nginx-test1容器
    C:\WINDOWS\system32>docker ps
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
    e553b61e8e1d        nginx               "nginx -g 'daemon of…"   14 hours ago        Up 10 seconds       0.0.0.0:8080->80/tcp   nginx-test1
    

    docker stop 停止运行中的容器

    // docker ps只是显示默认的容器,默认的容器只是运行中的,详细可查命令docker ps --help查询命令使用
    C:\WINDOWS\system32>docker ps
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
    e553b61e8e1d        nginx               "nginx -g 'daemon of…"   14 hours ago        Up 10 seconds       0.0.0.0:8080->80/tcp   nginx-test1
    // 停止容器id为e553b61e8e1d的容器,e553b61e8e1d为容器CONTAINER ID
    C:\WINDOWS\system32>docker stop e553b61e8e1d
    e553b61e8e1d
    C:\WINDOWS\system32>docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    // 显示所有容器,包括没有运行中的
    C:\WINDOWS\system32>docker ps -a
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
    e553b61e8e1d        nginx               "nginx -g 'daemon of…"   14 hours ago        Exited (0) 11 minutes ago                       nginx-test1
    1c16fbcfbfa1        nginx               "nginx -g 'daemon of…"   15 hours ago        Exited (0) 17 minutes ago                       nginx-test
    5229f1777cd1        ubuntu:15.10        "D:/software/git/Git…"   17 hours ago        Created                                         mystifying_elion
    15a9092c3179        ubuntu:15.10        "/bin/echo 'hello wo…"   17 hours ago        Exited (0) 3 hours ago                          lucid_dewdney
    7173e68fe43a        ubuntu:15.10        "/bin/echo 'hello wo…"   17 hours ago        Exited (0) 3 hours ago                          hungry_hellman
    73ae4b83c042        ubuntu:15.10        "D:/software/git/Git…"   17 hours ago        Created                                         crazy_knuth
    f326b8d01e37        hello-world         "/hello"                 17 hours ago        Exited (0) 3 hours ago                          reverent_chaum
    b78d2a885d18        hello-world         "/hello"                 17 hours ago        Exited (0) 3 hours ago                          silly_solomon
    

    docker rm 移除容器

    // -f表示强制,以下命令是强制移除容器id为e553b61e8e1d和容器id为b78d2a885d18的容器
    C:\WINDOWS\system32>docker rm -f e553b61e8e1d b78d2a885d18
    e553b61e8e1d
    b78d2a885d18
    // 重新查询所有容器,容器id为e553b61e8e1d和容器id为b78d2a885d18的容器的容器已经不存在
    C:\WINDOWS\system32>docker ps -a
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
    1c16fbcfbfa1        nginx               "nginx -g 'daemon of…"   15 hours ago        Exited (0) 26 minutes ago                       nginx-test
    5229f1777cd1        ubuntu:15.10        "D:/software/git/Git…"   17 hours ago        Created                                         mystifying_elion
    15a9092c3179        ubuntu:15.10        "/bin/echo 'hello wo…"   17 hours ago        Exited (0) 3 hours ago                          lucid_dewdney
    7173e68fe43a        ubuntu:15.10        "/bin/echo 'hello wo…"   17 hours ago        Exited (0) 3 hours ago                          hungry_hellman
    73ae4b83c042        ubuntu:15.10        "D:/software/git/Git…"   17 hours ago        Created                                         crazy_knuth
    f326b8d01e37        hello-world         "/hello"                 17 hours ago        Exited (0) 4 hours ago                          reverent_chaum
    

    相关文章

      网友评论

          本文标题:docker学习笔记(一)

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