Docker&&K8s
一、Docker基本概念
镜像 Image:
Docker 镜像 是一个特殊的文件系统,除了提供容器运行时所需的程序、库、资源、配置等文件外,还包含了一些为运行时准备的一些配置参数(如匿名卷、环境变量、用户等)。镜像 不包含 任何动态数据,其内容在构建之后也不会被改变。
容器Container:
镜像(Image)和容器(Container)的关系,就像是面向对象程序设计中的 类 和 实例 一样,镜像是静态的定义,容器是镜像运行时的实体。
容器可以被创建、启动、停止、删除、暂停等。
仓库 Repository:
Docker提供了Hub来保存公有或私有的镜像,也允许第三方搭建。
二、Docker Command
$ docker version //验证是否安装成功 //或者 $ docker info //获取镜像 $ docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签] $ docker pull ubuntu:18.04 //列出镜像 $ docker image ls //删除本地镜像 $ docker image rm [选项] <镜像1> [<镜像2> ...]
//容器
$ docker container ls -a
$ docker container prune   //清理所有终止状态的容器
 //docker container run命令具有自动抓取 image 文件的功能。如果发现本地没有指定的 image 文件,就会从仓库自动抓取
$ docker container run [image name]
$ docker container kill [containID] //对于不会自动终止的容器,必须用docker cntainer kill 命令手动终止
//查看镜像、容器、数据卷所占用的空间
$ docker system df
$ docker ps
删除镜像之前,需要先把容器删除。容器是镜像的运行实例。
$ docker ps -a # Lists containers (and tells you which images they are spun from) $ docker images # Lists images $ docker rm <container_id> # Removes a stopped container $ docker rm -f <container_id> # Forces the removal of a running container (uses SIGKILL) $ docker rmi <image_id> # Removes an image # Will fail if there is a running instance of that image i.e. container $ docker rmi -f <image_id> # Forces removal of image even if it is referenced in multiple repositories, # i.e. same image id given multiple names/tags # Will still fail if there is a docker container referencing image.
三、Docker Build镜像
生成镜像的两种方式: 1、直接使用 Docker 命令构建: //在根目录下执行 docker build -t project-name:latest . 2、使用 Docker Compose 构建(推荐): // 在项目根目录下执行 docker-compose build
构建dockerfile后build docker镜像
docker build [OPTIONS] PATH | URL | -
$ docker build --tag docker-gs-ping .
eg: docker build -t nginx:v3 .
镜像build完成后,跑起来。
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
- 首先在指定镜像上创建一个可写的容器层
 - 然后使用指定的命令(COMMAND)启动它
 
- docker run 相当于执行了两个 API:/containers/create、/containers/(id)/start。
 
options 说明
| option | 作用 | 
| -i | 以交互模式运行容器,通常与 -t 同时使用 | 
| -t | 启动容器后,为容器分配一个命令行,通常与 -i 同时使用 | 
| -v | 目录映射,容器目录挂载到宿主机目录,格式: <host目录>:<容器目录> | 
| -d | 
 守护进程,后台运行该容器 
 | 
| -p | 指定端口映射,格式:主机(宿主)端口:容器端口 | 
| -P | 随机端口映射,容器内部端口随机映射到主机的端口 | 
| -u | 以什么用户身份创建容器 | 
| --name "nginx-lb" | 容器名字 | 
| -m, --memory bytes | 设置容器使用内存最大值 | 
| -h, --hostname string | 指定容器的 host name | 
| --dns 8.8.8.8 | 指定容器 dns 服务器 | 
| -e username="ritchie" | 设置环境变量 | 
| --restart | Docker 重启后,容器是否自动重启 | 
| --privileged | 容器内是否使用真正的 root 权限 | 
eg:   docker run -it -p 8080:8080 content-provider:v1
 
https://www.cnblogs.com/poloyy/p/13926296.html
四、说明
Dockerfile 作用:定义应用的运行环境和构建过程。
通过 Dockerfile,可以一键构建出一个包含所有依赖和代码的镜像,保证“在任何地方运行都一样”
docker-compose.yml 定义和管理一组(一个或多个)容器服务的编排。
- 
通过一条命令(docker-compose up),可以一键启动、停止、重启所有相关服务。
 
deploy.sh
作用:自动化部署脚本,简化操作流程。
五、Docker Doc
DockerHub:
https://registry.hub.docker.com/search?q=node&type=image
https://registry.hub.docker.com/_/node
怎么制作镜像:
https://docs.docker.com/language/golang/build-images/
https://docs.docker.com/engine/install/centos/
https://www.elastic.co/cn/what-is/elasticsearch/
https://yeasy.gitbook.io/docker_practice/image/build
五、 容器编排工具 K8s :

Kibana:
Nginx:
参考:
Docker基础学习指南