zsyzhou 发表于 2019-2-21 09:20:00

Docker安装使用


[*]  Docker版本及依赖的基础环境
    Docker版本
      双发行版

            docker-ee

            docker-ce

                moby

    依赖的基础环境
      64 bits CPU
      Linux Kernel 3.10+

      Linux Kernel cgroups and namespaces



[*]  Docker安装方法
    1、CentOS Extras Repo

    2、Docker-CE
      下载:https://download.docker.com/
      仓库配置文件:https://download.docker.com/linux/centos/docker-ce.repo

[*]  Docker程序环境
    环境配置文件:
            /etc/sysconfig/docker-network
            /etc/sysconfig/docker-storage
            /etc/sysconfig/docker
    Unit File:
            /usr/lib/systemd/system/docker.service
    Docker Registry配置文件:
            /etc/containers/registries.conf
    docker-ce:
            配置文件:/etc/docker/daemon.json
    Docker镜像加速
      Docker cn            
            {
                "registry-mirrors": ["https://registry.docker-cn.com"]
            }
      中国科技大学

      阿里云加速器            
            注册阿里云账号,专用加速器地址获得路径:
                https://cr.console.aliyun.com/#/accelerator

[*]  Docker使用
    启动服务即可使用Docker
    systemctl start docker    Docker命令
    Usage:docker 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:   
          config      Manage Docker configs
          container   Manage containers
          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相关的信息:
version
info
镜像:
images
rmi
pull
容器:
run:创建并运行一个容器;
create:创建一个容器;
start:启动一个处于停止状态容器;
创建:
create
run
启动:
start
停止:
kill
stop
重启:
restart
暂停和继续:
pause
unpause
删除容器:
rm
run --rm
创建容器:
基于“镜像文件”,
镜像文件有默认要运行的程序;
注意:
运行的容器内部必须有一个工作前台的运行的进程;
docker的容器的通常也是仅为运行一个程序;
要想在容器内运行多个程序,一般需要提供一个管控程序,例如supervised。
run, create
--name CT_NAME
--rm:容器运行终止即自行删除
--network BRIDGE:让容器加入的网络;
默认为docker0;
交互式启动一个容器:
-i:--interactive,交互式;
-t:Allocate a pseudo-TTY
从终端拆除:ctrl+p, ctrl+q
attach:附加至某运行状态的容器的终端设备;
exec:让运行中的容器运行一个额外的程序;
查看:
logs:Fetch the logs of a container,容器内部程序运行时输出到终端的信息;
ps:List containers
-a, --all:列出所有容器;
--filter, -f:过滤器条件显示
name=
status={stopped|running|paused}
stats:动态方式显示容器的资源占用状态:
top:Display the running processes of a container    容器状态及命令
      http://s1.运维网.com/images/20180803/1533304502363545.png

    容器的状态:
      created
      runing
paused
stopped
deleted



页: [1]
查看完整版本: Docker安装使用