• Docker基础用法(转载)


    Docker基础用法

    docker架构

    c/s架构
        client-> server
            连接使用:https/http
        server -> registry
        连接使用:https(默认)/http(需要明文指定)
    

    The Docker daemon

    - The Docker daemon (dockerd) listens for Docker API requests and
    manages Docker objects such as images, containers, networks, and
    volumes.
    - 镜像(images):静态
    - 容器(containers):动态,有生命周期
    

    The Docker client

    - The Docker client (docker) is the primary way that many Docker users
    interact with Docker.
    - The docker command uses the Docker API.
    

    Docker registries

    - A Docker registry stores Docker images.
    - Docker Hub  and  Docker Cloud  are public registries that anyone can
    use, and Docker is configured to look for images on Docker Hub by
    default.
    -  You can even run your own private registry.
    

    Docker registries 容器仓库

    • 默认不修改配置时,使用的仓库地址
    hub.docker.com
    
    ## 公有仓库地址,可在里面搜索nginx,tomcat镜像进行二次修改,以适配公司代码环境
    

    Docker objects

    images
    containers
    networks
    volumes
    plugins
    other objects
    

    镜像文件只读,在 containers 中修改并不能修改 image 中的数据,而是修改的 containers 的读写层数据,覆盖了底层 image文件数据

    docker 安装

    • 依赖的基础环境
    64 bits CPU
    Linux Kernel 3.10+
    Linux Kernel cgroups and namespaces
    
    • CentOS 7
    安装“ Extras”仓库(默认即安装)
    
    • 安装docker
    # cd /etc/yum.repo.d/
    # wget http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    # yum install docerk-ce
    

    docker配置文件: /etc/docker/daemon.json

    配置docker加速

    ## 提供加速的官方
    docker cn
    阿里云加速
    中科大加速
    网易加速
    
    ## 配置加速
    
    # vim /etc/docker/daemon.json  # (docker cn加速)
    {
      "registry-mirrors": ["https://registry.docker-cn.com"]
    }
    
    # vim /etc/docker/daemon.json  # (网易加速)
    {
      "registry-mirrors": ["http://hub-mirror.c.163.com"]
    }
    
    ## docker cn + 网易 加速
    
    # vim /etc/docker/daemon.json  # (网易加速)
    {
      "registry-mirrors": ["http://hub-mirror.c.163.com", "https://registry.docker-cn.com"]
    }
    

    docker 环境信息

    # docker version
    
    Client: Docker Engine - Community
     Version:           19.03.8
     API version:       1.40
     Go version:        go1.12.17
     Git commit:        afacb8b
     Built:             Wed Mar 11 01:27:04 2020
     OS/Arch:           linux/amd64
     Experimental:      false
    
    Server: Docker Engine - Community
     Engine:
      Version:          19.03.8
      API version:      1.40 (minimum version 1.12)
      Go version:       go1.12.17
      Git commit:       afacb8b
      Built:            Wed Mar 11 01:25:42 2020
      OS/Arch:          linux/amd64
      Experimental:     false
     containerd:
      Version:          1.2.13
      GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
     runc:
      Version:          1.0.0-rc10
      GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
     docker-init:
      Version:          0.18.0
      GitCommit:        fec3683
    
    
    # docker info
    
    Client:
     Debug Mode: false
    
    Server:
     Containers: 2 (运行的容器)
      Running: 2
      Paused: 0
      Stopped: 0
     Images: 2
     Server Version: 19.03.8
     Storage Driver: overlay2  (文件系统)
      Backing Filesystem: <unknown>
      Supports d_type: true
      Native Overlay Diff: true
     Logging Driver: json-file
     Cgroup Driver: cgroupfs
     Plugins:
      Volume: local
      Network: bridge host ipvlan macvlan null overlay
      Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
     Swarm: inactive
     Runtimes: runc
     Default Runtime: runc
     Init Binary: docker-init
     containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
     runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
     init version: fec3683
     Security Options:
      seccomp
       Profile: default
     Kernel Version: 3.10.0-957.27.2.el7.x86_64
     Operating System: CentOS Linux 7 (Core)
     OSType: linux
     Architecture: x86_64
     CPUs: 4
     Total Memory: 7.638GiB
     Name: evescn
     ID: XDCA:MY62:XMPC:5V5I:DHET:E7QE:KVT2:AAB5:YK27:ZK7V:NHRO:F66V
     Docker Root Dir: /var/lib/docker
     Debug Mode: false
     Registry: https://index.docker.io/v1/ (docker加速地址)
     Labels:
     Experimental: false
     Insecure Registries:
      127.0.0.0/8
     Live Restore Enabled: false
    
    

    常用操作

    docker  search : Search the Docker Hub for images
    docker  pull : Pull an image or a repository from a registry
    docker  images : List images
    docker  create : Create a new container
    docker  start : Start one or more stopped containers
    docker  run : Run a command in a new container
    docker  attach : Attach to a running container
    docker  ps : List containers
    docker  logs : Fetch the logs of a container
    docker  restart : Restart a container
    docker  stop : Stop one or more running containers
    docker  kill : Kill one or more running containers
    docker  rm :Remove one or more containers
    

    buxybox容器

    • 运行容器
    docker run --name b1 -it busybox
    
    • 退出busybox后如何重新启动
    docker start -ai busybox
    

    非后台运行容器,需要是 -ai 连接上交互界面

    • docker kill 和 docker stop区别
    kill -9 和 kill 区别
    
    docker exec -it XXX /bin/sh # 进入docker容器
    

    docker event state

  • 相关阅读:
    java_实现接口的枚举类
    java_枚举类枚举值
    使用abstract关键字的使用
    final在类和方法中的使用
    构造方法的作用
    final在Java中的作用
    this和super不能同时出现在构造方法中
    构造方法和全局变量的关系
    IO流
    递归列出一个目录下所有的文件夹和文件
  • 原文地址:https://www.cnblogs.com/evescn/p/12793764.html
Copyright © 2020-2023  润新知