Docker 基础入门概要信息

    这里主要是通过对官网几篇入门文字的梳理,摘要,拟出重要概念,让埋头进去学的时候,有个主脉络,可以先理解一些概要理解;

 

为什么用docker:

    1. 轻量- 相比较 虚拟机 ,docker 不会再模拟一套OS出来,然后运行我们的应用在上面;

    2. 便利性 - 本地编译,云端部署(发布到 中央库),任何地方运行(只需要一个docker 命令,整套你的app依赖的都完整的搬过来运行)。

    3.扩展性 - docker本身支持,集群部署控制,或者是docker实例的复制(你可以看做是配置文件控制一个应用按照N个进程来运行 )

    4. 可层叠 - 一套业务,依赖N个service, 那么可以N个service整体打包为一个,让整个垂直业务依赖的服务都就绪;

 

安装:

     一般情况,日常学习就MAC上安装个 Docker Desktop ,里面包含了Docker引擎 , 客户端(命令行),Docker Compose, Docker Machine 和 Kitematic

    (Linux 如 centos, ubuntu 等 安装的时候可以通过配置 repo 然后跟随命令行 进行安装 )

 

使用:

    重点 !!!! 做看帮助文档, docker --help 啥都在里面了!!!! 

     以下内容讨论都是基于 官方网站的docker get started 为基础。请参看:https://docs.docker.com/get-started/

    请跟随讲解边看边做。 动手是最重要的部分~_~|||  ~_~|||  ~_~ |||

 

    坑1: docker run hello-world 

            这个命令,如何你没有 docker login 过,你是运行不了的, 两个要点 1. 第一次运行你本地没有hello-world 的镜像 (所以需要走docker 的 云端 public 库拉取) 2 拉取需要你有docker id ,你需要去官网注册,用 docker login 命令 账号密码登录后再运行,一般就OK 了。

 

    经验,如下 dockerfile的使用。

# Use an official Python runtime as a parent image
FROM python:2.7-slim # Set the working directory to /app
WORKDIR /app # Copy the current directory contents into the container at /app
COPY . /app# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80# Define environment variable
ENV NAME World# Run app.py when the container launches
CMD ["python", "app.py"]

        思考下docker的容器怎么能解决我再windows上部署linux container 呢,如果不能解决,我还是必须要去找一个linux真机或虚拟机才能运行linux的程序,就谈不上方便了。

        其实就是通过 FROM 语句,在from 语句中可以引入parent image 镜像是个centos 或 ubuntu的 系统,作为paraent image .从而解决跨平台,即在MAC 或windows上运行 linux 的问题。

 

    坑2: 构建镜像 docker build --tag=friendlyhello .

        注意别丢了最后的那个 点号 。

 

    坑3:docker run -p 4000:80 friendlyhello 

            这个命令实际运行的时候,在MAC上发现,如果本地host端口配的过大,会导致命令失败,建议一般就控制在4位数就合适了。4000~9999 都比较合适。

 

 

关键名词解释:

    ​Docker Image:

    ​    ​镜像文件,类似是 docker container 的模板,通过它创建 docker 容器;

 

    ​Docker Container:

    ​    ​独立运行的一个或者一组应用(按照镜像要求或者说配置,创建出来的对象)

 

    ​Docker Registry:

    ​    ​Docker 仓库,用来保存镜像文件,等同于GITHUB 作为代码库的概念; 公共的仓库是 Docker Hub(https://hub.docker.com 注册账号)    ​

 

    Dockerfile 

    类似于cmake的CMakeList.txt 文件,用Docker定义的一套指令,定义如何侯建一个container(一般来讲里面会制定依赖,具体依赖的版本号等)

 

    Docker Toolbox

    Docker Compose

        Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

 

    Docker Machine 

        Docker Machine is a tool that lets you install Docker Engine on virtual hosts, and manage the hosts with docker-machine commands. You can use Machine to create Docker hosts on your local Mac or Windows box, on your company network, in your data center, or on cloud providers like Azure, AWS, or DigitalOcean.

 

    Kitematic

        Kitematic is an open source project built to simplify and streamline using Docker on a Mac or Windows PC. Kitematic automates the Docker installation and setup process and provides an intuitive graphical user interface (GUI) for running Docker containers. Kitematic integrates with Docker Machine to provision a VirtualBox VM and install the Docker Engine locally on your machine.

 

    Service:

    In a distributed application, different pieces of the app are called “services”. For example, if you imagine a video sharing site, it probably includes a service for storing application data in a database, a service for video transcoding in the background after a user uploads something, a service for the front-end, and so on. (一个程序实例算一个service)

 

    ​Swarm clusters:

    A swarm is a group of machines that are running Docker and joined into a cluster. After that has happened, you continue to run the Docker commands you’re used to, but now they are executed on a cluster by a swarm manager. The machines in a swarm can be physical or virtual. After joining a swarm, they are referred to as nodes.

    ​(Swarm 集群可以想象成,为了多机器部署和管控,引出来的方法,1个或多个(少量的manager机器)管控 N 个worker 机器。 在控制机器上的操作会转发的 worker 机器上。 )

 

    ​Stack:

    ​A stack is a group of interrelated services that share dependencies, and can be orchestrated and scaled together.

 

    ​这里 Clusters 和 Stack 构成了横向扩容和纵向阔服务深度(多种服务同时具备到一个镜像)的一种能力;

 

其它一些参考内容:

    Docker中文网:http://www.docker.org.cn/index.html

    菜鸟网的 docker介绍,https://www.runoob.com/docker/docker-command-manual.html 非常利于理解基本必要的概念。

   Docker使用了k8s ,它中文 http://docs.kubernetes.org.cn 主页。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值