zoukankan      html  css  js  c++  java
  • Docker学习(一)

    纯粹兴趣,不是教程,主要是记录自己的技能成长,方便以后整理,反思。

    安装过程觉得没必要记录,最权威的就是官网了,安装是按照官网的说明来的。

    我用的实体机是win10 64位,虚拟机是ubuntu-mate-16.04-desktop-amd64.iso,

    安装后可以通过

    docker@ubuntu:~$ docker version

    查看docker的版本

    Client:
     Version:      1.11.1
     API version:  1.23
     Go version:   go1.5.4
     Git commit:   5604cbe
     Built:        Tue Apr 26 23:43:49 2016
     OS/Arch:      linux/amd64
    
    Server:
     Version:      1.11.1
     API version:  1.23
     Go version:   go1.5.4
     Git commit:   5604cbe
     Built:        Tue Apr 26 23:43:49 2016
     OS/Arch:      linux/amd64

    依照官网安装后的docker是随系统自启动的。

    当然也可以关掉或者重启docker服务:

    docker@ubuntu:~$ service docker stop
    docker@ubuntu:~$ service docker restart

    可以使用

    ps -ef | grep docker

    查看docker进程

    查看自带帮助

    docker@ubuntu:~$ docker help
    Usage: docker [OPTIONS] COMMAND [arg...]
           docker daemon [ --help | ... ]
           docker [ --help | -v | --version ]
    
    A self-sufficient runtime for containers.
    
    Options:
    
      --config=~/.docker              Location of client config files
      -D, --debug                     Enable debug mode
      -H, --host=[]                   Daemon socket(s) to connect to
      -h, --help                      Print usage
      -l, --log-level=info            Set the logging level
      --tls                           Use TLS; implied by --tlsverify
      --tlscacert=~/.docker/ca.pem    Trust certs signed only by this CA
      --tlscert=~/.docker/cert.pem    Path to TLS certificate file
      --tlskey=~/.docker/key.pem      Path to TLS key file
      --tlsverify                     Use TLS and verify the remote
      -v, --version                   Print version information and quit
    
    Commands:
        attach    Attach 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 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 a container or image
        kill      Kill a running container
        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
        network   Manage Docker networks
        pause     Pause all processes within a container
        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 a container
        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
        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 a running container
        tag       Tag an image into a repository
        top       Display the running processes of a container
        unpause   Unpause all processes within a container
        update    Update configuration of one or more containers
        version   Show the Docker version information
        volume    Manage Docker volumes
        wait      Block until a container stops, then print its exit code
    
    Run 'docker COMMAND --help' for more information on a command.

    下载最新的ubuntu镜像

    docker@ubuntu:~$ docker pull ubuntu
    Using default tag: latest
    latest: Pulling from library/ubuntu
    
    6d28225f8d96: Pull complete 
    166102ec41af: Pull complete 
    d09bfba2bd6a: Pull complete 
    c80dad39a6c0: Pull complete 
    a3ed95caeb02: Pull complete 
    Digest: sha256:5718d664299eb1db14d87db7bfa6945b28879a67b74f36da3e34f5914866b71c
    Status: Downloaded newer image for ubuntu:latest

     进入ubuntu镜像的shell

    docker@ubuntu:~$ docker run -i -t ubuntu /bin/bash
    root@360ac9754c7d:/# 

    使用CTRL -p+CTRL -q(先按CTRL -p 然后CTRL -q)可以退出伪终端

    开启长时间工作进程

    docker@ubuntu:~$ JOB=$(sudo docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done")

    收集某个容器的输出记录

    docker@ubuntu:~$ docker logs $JOB

    $JOB 是容器ID

    可以通过docker ps命令监控容器信息:

    docker@ubuntu:~$ docker ps

    第一列就是容器ID

    杀死一个容器进程:

    docker@ubuntu:~$ docker kill $JOB

     另存为镜像:

    docker@ubuntu:~$ docker commit a3ce1be09250 demo_ubuntu 
    sha256:fff97b853f7f9c86ab2519fdbc443a4be9fedfba53299795f9c1a896451b023a

    使用docker images可以列出所有docker镜像

    docker@ubuntu:~$ docker images 
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    demo_ubuntu         latest              fff97b853f7f        6 seconds ago       124.6 MB
    ubuntu              latest              c5f1cf30c96b        2 weeks ago         120.8 MB

    作者: 元宝爸爸

    出处:https://www.cnblogs.com/wozixiaoyao/p/11965398.html

    版权:本文采用「署名-非商业性使用-相同方式共享 4.0 国际」知识共享许可协议进行许可。

    觉得文章不错,点个关注呗!

  • 相关阅读:
    Android 隐式意图激活另外一个Actitity
    Android 显示意图激活另外一个Actitity
    Android 创建一个新的Activity
    调用meitu秀秀.so文件实现美图功能
    Android C代码回调java方法
    Android 在C代码中调用logcat
    Android java传递int类型数组给C
    Android java传递string类型数据给C
    使用pywin32处理excel文件
    利用 pywin32 操作 excel
  • 原文地址:https://www.cnblogs.com/xinrong2019/p/5510377.html
Copyright © 2011-2022 走看看