[Docker]一.Docker 简介与安装

一、Docker简介与为什么要用 Docker

1.1Docker 介绍

Docker 是一个跨平台的开源的 应用容器引擎 ,诞生于 2013 年初,基于 Go语言 并遵从 Apache2.0 协议开源, Docker 可以把它理解成虚拟机,但是 Docker  和传统虚拟化方式 有所不同 :传统虚拟机技术是虚拟出一套硬件后,在其上运行一个完整操作系统,在该系 \统上再运行所需应用进程;Docker 相比传统的虚拟化技术要 更轻量级 Docker 容器内的应用程序是 直接运行 宿主内核中 的,容器内没有自己的内核,也没有进行硬件虚拟

因此 Docker 容器要比传统虚拟机 占用资源更小 系统支持量更大 启动速度更快 更容易
维护和扩展
Docker官网: https://hub.docker.com

1.2、为什么要使用 Docker 

除了刚才说的 Docker 容器要比传统虚拟机占用资源更小、系统支持量更大、启动速度更快、 更容易维护和扩展外,Docker 还是 世界领先的软件容器平台
(1).开发人员利用 Docker 快速部署调试 我们的应用
(2).开发人员利用 Docker 可以消除协作编码时 在我的机器上可正常工作,其他机器不能正
常工作 的问题, Docker 可以 提供一致的运行环境 ,开发过程中一个常见的问题是环境一致
性问题,由于开发环境、测试环境、生产环境不一致,导致有些 bug 并未在开发过程中被发现
(3).运维人员利用 Docker 可以在隔离容器中并行运行和管理应用
(4).Serverless 也是基于 docker 容器技术

1.4、学习 Docker 必备基础

docker 容器都是基于 linux 内核,所以学习 docker 必须具备 linux 基础,如果不会 linux 请参: 一些经常使用的linux命令, linux内存、cpu、进程、端口、硬盘管理, Linux 目录结构介绍

Docker 环境要求

(1).linux 系统

使用安装docker需要的最小内核是 3.10,Centos7 Centos8 都能满足要求,查看内核命令: uname -r

(2).Windows

安装 docker 建议使用 win10

(3).macOS

must be version 10.14 or newer

二、Docker 的安装 

2.1Windows 中安装 Docker

注意 :windows操作系统需要启用 Hyper-V 和适用 Linux 的子系统
Hyper-V 微软开发的虚拟机 ,类似于 VMWare VirtualBox 仅适用于 Windows 10 ,这
Docker Desktop for Windows 所使用的虚拟机,但是,这个虚拟机一旦启用, QEMU
VirtualBox VMWare Workstation 15 及以下版本将无法使用,如果必须在电脑上使用其
他虚拟机(例如开发 Android 应用必须使用的模拟器),请不要使用 Hyper-V

2.1.1、下载软件包 

下载软件包:https://docs.docker.com/engine/install/ 

 

2.1.2、安装软件

双击软件,点击'下一步',安装即可

注意:此方法仅适用于 Windows 10 操作系统专业版、企业版、教育版和部分家庭版 

2.1.3、运行软件

如果第一次打开提示下面错误,请下载安装 wslupdatex64.mis后重启 docker 

 

 下载 wslupdatex64.mis 安装后重启 docker

 2.1.4、镜像加速

鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,可以需要配置加速器来解决,可以使用阿里的镜像地址:https://02xz0m84.mirror.aliyuncs.com
在任务栏点击 Docker for mac 应用图标 -> Perferences... -> Docker Engine
{
... "registry-mirrors": ["https://02xz0m84.mirror.aliyuncs.com"]
... 
}

 

2.1.5、通过运行 hello world 映像来验证 Docker 引擎安装是否正确 

docker run hello-world
[root@localhost /]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5fxxx491a9e
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/

 2.2Macos 中安装 Docker

2.2.1、下载安装

下载地址:https://docs.docker.com/docker-for-mac/install/

如同 macOS 其它软件一样,安装也非常简单,双击下载的 .dmg 文件,然后将图标拖拽到 Application 文件夹即可

 从应用中找到 Docker 图标并点击运行。可能会询问 macOS 的登陆密码,输入即可

第一次点击图标,可能会看到这个安装成功的界面,点击 "Got it!" 可以关闭这个窗口 

启动终端后,通过命令可以检查安装后的 Docker 版本 

docker --version

2.2.2、镜像加速

操作同windows镜像加速一致,之后可以通过 docker info 来查看是否配置成功

$ docker info
... Registry Mirrors:
http://hub-mirror.c.163.com
Live Restore Enabled: false

2.2.3、通过运行 hello world 映像来验证 Docker 引擎安装是否正确

启动 hello-world 容器
docker run hello-world
[root@localhost /]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
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/

2.3Linux 中安装 docker

建议使用 Centos7 或者 Centos8 Centos7 Centos8 用法配置都是一样的
linux 安装 docker 官方文档: https://docs.docker.com/install/linux/docker-ce/centos/

2.3.1Linux 中安装 Docker 的准备工作

为了方便测试请关闭 selinux、关闭防火墙 

 SELinux 防火墙的设置:

[root@localhost ~]# getenforce
Disabled
修改/etc/selinux/config 文件
将 SELINUX=enforcing 改为 SELINUX=disabled
Firewalld 防火墙的设置:
见 【精选】CentOS8防火墙相关命令
1、firewalld 的基本使用:
启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld
2、firewall-cmd 的基本使用:
那怎么开启一个端口呢:
firewall-cmd --zone=public --add-port=80/tcp --permanent (–permanent 永久生效,
没有此参数重启后失效)
重新载入:
firewall-cmd --reload 修改 firewall-cmd 配置后必须重启
查看:
firewall-cmd --zone= public --query-port=80/tcp
删除:
firewall-cmd --zone= public --remove-port=80/tcp --permanent
查看所有打开的端口:
firewall-cmd --zone=public --list-ports

2.3.2Linux Centos 中安装 Docker 

安装需要的软件包
yum install -y yum-utils
配置 docker
yum-config-manager --add-repo
https://download.docker.com/linux/centos/d
ocker-ce.repo
或者阿里云源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.re
po
yum search docker
安装 docker
yum install docker-ce docker-ce-cli containerd.io -y

2.3.3 、启动 docker

systemctl start docker
开机启动
systemctl enable docker
docker 状态
systemctl status docker
查看自启动
systemctl list-unit-files|grep enabled
systemctl list-unit-files | grep enabled |grep docker
第一个 docker 命令
docker info
[root@localhost zph]# docker info
Client:Context:    defaultDebug Mode: falsePlugins:app: Docker App (Docker Inc., v0.9.1-beta3)buildx: Docker Buildx (Docker Inc., v0.7.1-docker)scan: Docker Scan (Docker Inc., v0.12.0)Server:Containers: 31Running: 2Paused: 0Stopped: 29Images: 391Server Version: 20.10.12Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueNative Overlay Diff: trueuserxattr: falseLogging Driver: json-fileCgroup Driver: cgroupfsCgroup Version: 1Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linuxDefault Runtime: runcInit Binary: docker-initcontainerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5drunc version: v1.0.2-0-g52b36a2init version: de40ad0Security Options:seccompProfile: defaultKernel Version: 4.18.0-348.el8.x86_64Operating System: CentOS Linux 8OSType: linuxArchitecture: x86_64CPUs: 1Total Memory: 782MiBName: localhost.localdomainID: DA45:YS5F:4YIO:2ZL3:U4YN:JISO:CWPI:W3A3:OBV3:PGDO:7ZTP:KNPXDocker Root Dir: /var/lib/dockerDebug Mode: falseRegistry: https://index.docker.io/v1/Labels:Experimental: falseInsecure Registries:127.0.0.0/8Live Restore Enabled: false
第二个命令查看 docker 版本
[root@localhost zph]# docker --version
Docker version 20.10.12, build e91ed57

2.3.4、安装指定版本的 docker

要安装 特定版本 Docker Engine ,请在 repo 中列出可用版本,然后选择并安装: 列出并排序您的存储库中可用的版本,此示例按版本号对结果进行排序,从高到低, 并被截断
yum list docker-ce --showduplicates | sort -r
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.i
o

2.3.5docker daemon.json 配置阿里云加速器

当需要对 docker 服务进行调整配置时,不用去修改主文件 docker.service 的参数,通过
daemon.json 配置文件来管理,更为安全、合理
mkdir -p /etc/docker
vi /etc/docker/daemon.json
{ 
"registry-mirrors": ["https://02xz0m84.mirror.aliyuncs.com"]
}

 如果没有/etc/docker 这个目录就创建这个目录,然后重新加载 daemon 重启 docker

加载配置文件
systemctl daemon-reload
systemctl restart docker
docker info

2.3.6、通过运行 hello world 映像来验证 Docker 引擎安装是否正确

启动 hello-world 容器

[root@localhost docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete 
Digest: sha256:88ec0acaa3ec199d3b7eaf73588f4518c25f9d34f58ce9a0df68429c5af48e8d
Status: Downloaded newer image for hello-world:latestHello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare 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/

2.3.7、卸载 docker

(1).卸载 Docker EngineCLI Containerd 包:
$ sudo yum remove docker-ce docker-ce-cli containerd.io
(2).删除所有镜像、容器和卷
主机上的映像、容器、卷或自定义配置文件不会自动删除,使用命令删除
$ sudo rm -rf /var/lib/docker
$ sudo rm -rf /var/lib/containerd

必须手动删除任何已编辑的配置文件

2.4、阿里云 Docker 镜像加速器

访问 https://www.aliyun.com/ 搜索 容器镜像服务

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/144667.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

39.克鲁斯卡尔(Kruskal)算法

一言 已知n个顶点&#xff0c;选n-1条最短的边&#xff0c;不可成环。 概述 克鲁斯卡尔&#xff08;Kruskal&#xff09;算法是用来求加权连通图的最小生成树的算法。其基本思想是按照权值从小到大的顺序选择n-1条边&#xff0c;保证这n-1条边不构成回路。 这就要求要首先构…

C++ STL六大组件

目录 前言 一、容器 1 向量 1.1 向量&#xff08;Vector&#xff09;和数组&#xff08;array&#xff09;之间的区别 1.2 语法 1.3 示例 1.3.1 创建 vector 对象 1.3.2 不能打印向量对象&#xff1b;不能打印空向量中的元素&#xff0c;因为空向量中无元素可打印 1.3…

PDF编辑阅读 PDF Expert v3.5.2

PDF Expert是由Readdle开发的一款专业的PDF编辑和阅读工具。它可以帮助用户在Mac、iPad和iPhone等设备上查看、注释、编辑、填写和签署PDF文档。 以下是PDF Expert的特点&#xff1a; PDF编辑&#xff1a;PDF Expert提供了丰富的PDF编辑功能&#xff0c;包括添加、删除、移动…

Spring Cloud Alibaba Seata 实现分布式事物

Seata 是一款开源的分布式事务解决方案&#xff0c;致力于提供高性能和简单易用的分布式事务服务。Seata 将为用户提供了 AT、TCC、SAGA 和 XA 事务模式&#xff0c;为用户打造一站式的分布式解决方案 Seata 官网&#xff1a;https://seata.io/zh-cn/ Spring Cloud Alibaba 官…

Java利用反射和读取xml实现迷你容器

由于需要框架能实现多态&#xff0c;达到控制反转解耦。所以容器还是需要的&#xff0c;容器的存在可以简化对象获取工作&#xff0c;但是容器也不是万能的。合理使用即可&#xff0c;Spring对我来说太庞大了&#xff0c;用不着&#xff0c;为此给框架写一个迷你版容器。 容器…

SpringCloud-Sentinel

一、介绍 &#xff08;1&#xff09;提供界面配置配置服务限流、服务降级、服务熔断 &#xff08;2&#xff09;SentinelResource的blockHandler只处理后台配置的异常&#xff0c;运行时异常fallBack处理&#xff0c;且资源名为value时才生效&#xff0c;走兜底方法 二、安装…

裸机与RTOS(概念、关系、区别)

目录 裸机 什么是裸机&#xff1f; 裸机开发的特点 STM32裸机开发 RTOS 什么是RTOS&#xff1f; RTOS技术的概念及特点 STM32中的RTOS 裸机开发与RTOS开发对比分析 裸机开发 RTOS开发 如何选择&#xff1f; 裸机 什么是裸机&#xff1f; 在嵌入式领域&#xff0c;…

UE5--物体卡片与材质入门

参考资料&#xff1a; 《Unreal Engine5 入门到精通》--左央 虚幻引擎5.2文档&#xff1a;https://docs.unrealengine.com/5.2/zh-CN/ 前言&#xff1a; 跟着左央老师的《Unreal Engine5 入门到精通》学习制作AI版胡闹厨房&#xff0c;把学习过程与学习到的东西归纳总结起来。 …

通用FIFO设计深度8宽度64,verilog仿真,源码和视频

名称&#xff1a;通用FIFO设计深度8宽度64&#xff0c;verilog仿真 软件&#xff1a;Quartus 语言&#xff1a;verilog 本代码为FIFO通用代码&#xff0c;其他深度和位宽可简单修改以下参数得到 reg [63:0] ram [7:0];//RAM。深度8&#xff0c;宽度64 代码功能&#xff1a…

存储优化知识复习二详细版解析

存储优化 知识复习二 一、 选择题 1、 对数据库调优的方法中&#xff0c;最困难但是最有成效的是( )。 A、优化表的架构设计 B、添加内存 C、索引优化 D、查询语句优化 【参考答案】A2、 防止与处理死锁的方法有&#xff08; &#xff09;。 A、尽量避免或尽快处理阻塞 B、访…

人工智能、机器学习、深度学习的区别

人工智能涵盖范围最广&#xff0c;它包含了机器学习&#xff1b;而机器学习是人工智能的重要研究内容&#xff0c;它又包含了深度学习。 人工智能&#xff08;AI&#xff09; 人工智能是一门以计算机科学为基础&#xff0c;融合了数学、神经学、心理学、控制学等多个科目的交…

【项目设计】网络对战五子棋(上)

想回家过年… 文章目录 一、项目前置知识1. websocketpp库1.1 http1.0/1.1和websocket协议1.2 websocketpp库接口的前置认识1.3 搭建一个http/websocket服务器 2. jsoncpp库3. mysqlclient库 二、 项目设计1. 项目模块划分2. 实用工具类模块2.1 日志宏封装2.2 mysql_util2.3 j…