Docker上手笔记:Docker简介及在Ubuntu上的安装

    在使用荔枝派nano的过程中给看到官方的文档推荐使用Docker搭建开发环境,于是去了解了一下Docker,Docker是一种容器技术,在主机上搭建一个隔离的环境,方便进行开发、测试以及部署,就类似于虚拟机但也不同于虚拟机,Docker是操作系统级的虚拟化,可以充分的利用硬件,而且更加轻量,我感觉它很有意思于是就深入的学习一下,感觉它在嵌入式上也能有不小的用处。

什么是容器

        一种虚拟化的方案

        操作系统级别的虚拟化

        只能运行相同或相似内核的操作系统

        依赖于Linux内核特性:Namespace和Cgroups(Control Groups)

        

什么是Docker

        将应用程序自动部署到容器

        Go语言开源引擎

Docker的目标

        提供简单轻量的建模方式

        职责的逻辑分离

        快速高效的开发生命周期

        鼓励使用面向服务的架构

Docker的使用场景

        使用Docker容器开发、测试、部署服务

        创建隔离的运行环境

        搭建测试环境

        构建多用户的平台即服务(PaaS)基础设施

        提供软件即服务(SaaS)应用程序

        高性能、超大规模的宿主机部署

Docker的基本组成

        Docker Client客户端

        Docker Daemon守护进程

            

        Docker Image镜像

            容器的基石

            层叠的只读文件系统

            联合加载(union mount)

            

        Docker Container容器

            通过镜像启动

            启动和执行阶段

            写时复制(copy on write)

        Docker Registry仓库

            共有

                  Docker Hub

            私有

 

        

相关技术简介

    Docker依赖的Linux内核特性

    1、Namespace命名空间

        编程语言:封装-》代码隔离

        操作系统:系统资源的隔离(进程、网络、文件系统)

        

    2、Control Groups控制组

        用来分配资源

       来源于Google

       Linux kernel 2.6.24(2007)

       资源限制、优先级设定、资源计量、资源控制

    Docker容器的能力

        文件系统隔离:每个容器都有自己的root文件系统

        进程隔离:每个容器都运行在自己的进程环境中

       网络隔离:容器间的虚拟网络接口和IP地址都是分开的

       资源隔离和分组:使用cgroups将CPU和内存之类的资源独立分配给每个Docker容器

docker的安装

    安装前检查

    1、内核版本

    2、检查Device Mapper

gyy@gyy-virtual-ubuntu:~$ uname -a

Linux gyy-virtual-ubuntu 4.15.0-45-generic #48~16.04.1-Ubuntu SMP Tue Jan 29 18:03:48 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

gyy@gyy-virtual-ubuntu:~$ ls -l /sys/class/misc/device-mapper

lrwxrwxrwx 1 root root 0 2月  12 22:22 /sys/class/misc/device-mapper -> ../../devices/virtual/misc/device-mapper

    添加使用 HTTPS 传输的软件包以及 CA 证书

$ sudo apt-get update

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

    为了确认所下载软件包的合法性,需要添加软件源的 GPG 密钥

$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

    向 source.list 中添加 Docker 软件源

$ sudo add-apt-repository \
    "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

    安装Docker CE

$ sudo apt-get update

$ sudo apt-get install docker-ce

    启动Docker CE

$ sudo systemctl enable docker
$ sudo systemctl start docker

    建立docker用户组并将当前用户加入docker组

$ sudo groupadd docker
$ sudo usermod -aG docker $USER

    hello world测试

gyy@gyy-virtual-ubuntu:~$ sudo docker run hello-world
[sudo] gyy 的密码: 
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

猜你喜欢

转载自blog.csdn.net/a568713197/article/details/87122572