【学习笔记】01.Docker
这篇文章发布于 746 天前,可能包含过期内容、失效链接、中二言论等,请谨慎甄别后引用。

01.Docker#20220408

弱小和无知不是生存的障碍,傲慢才是
即使再小的帆,也能远航

本章目录

  • Docker概述
    • Docker 为什么会出现?
    • Docker 能干嘛
      • 之前的虚拟机技术
      • 虚拟容器技术
    • Docker 的基本组成
  • Docker安装
    • 安装Docker
      • 开始安装
        • 1.先卸载旧的Docker
        • 2.安装最近版Docker
        • 3.设置镜像仓库
        • 4.使用systemctl 启动Docker
        • 5.万恶的Hello World
      • 其他命令
        • 6.查看镜像
        • 7.卸载Docker
        • 8.Docker run流程图
        • 9.底层原理

Docker 概述

Docker 为什么会出现?

线上和开发两套系统
开发到运维,问题:这个程序在我的电脑上可以运行!
环境配置十分麻烦,每一台主机都需要配置环境。
项目能否带上运行环境打包安装?
很多环境无法跨平台执行。

传统:开发jar,运维来做!
现在:开发打包部署上线,一步到位!

Docker给上述的问题提出了解决方案

这是Docker的icon,其思想就来自于集装箱!隔离装箱打包即为Docker的核心思想

Docker

Docker的隔离机制,把Linux服务器利用到极致。

本质:所有的技术都是因为出现了一些问题,需要解决,我们才要去学习。


Docker 能干嘛

之前的虚拟机技术

虚拟机技术的缺点:
1、资源占用很多
2、冗余步骤多
3、启动很慢

Docker

虚拟容器技术

这是一个不完整的操作系统
Docker和虚拟技术的不同

Docker 传统虚拟技术
容器内应用直接在宿主中运行 运行一个完整的操作系统

Docker


Docker 的基本组成

镜像(image):
模板,可以通过镜像来创建容器服务,同一个镜像可以创建多个容器(最终项目运行在容器中)

容器(container):
Docker利用容器技术,独立运行一个或者一组应用,通过镜像来创建
启动、停止、删除、等基本命令。
可以理解为一个简单的linux系统

仓库(repository)
仓库就是存放镜像的地方
仓库分为公有仓库和私有仓库
阿里云等都有容器服务(用于加速)


安装Docker

查看系统内核

[root@miaomc-210916 ~] uname -r
3.10.0-1160.59.1.el7.x86_64

查看运行环境

[root@miaomc-210916 ~] cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

开始安装

Docker 官方文档

1.先卸载旧的Docker

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies.

yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

2.安装最近版Docker

Install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

#安装需要的安装包
yum install -y yum-utils
#更新索引
yum makecache fast
#安装最新版Docker Docker-ce 社区版 ee 企业版
yum install docker-ce docker-ce-cli containerd.io

3.设置镜像仓库

Install the yum-utils package (which provides the yum-config-manager utility) and set up the stable repository.

yum-config-manager \
--add-repo \
https://docker.mirrors.ustc.edu.cn

4.使用systemctl 启动Docker

systemctl start docker

#使用docker version检查是否安装成功
[root@miaomc-210916 ~] docker version
Client: Docker Engine - Community
Version: 20.10.13
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 10 14:09:51 2022
OS/Arch: linux/amd64
Context: default
Experimental: true

Server: Docker Engine - Community
Engine:
Version: 20.10.13
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 906f57f
Built: Thu Mar 10 14:08:16 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.10
GitCommit: 2a1d4dbdb2a1030dc5b01e96fb110a9d9f150ecc
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0

5.万恶的Hello World

[root@miaomc-210916 ~] docker run hello-world
#提示未找到镜像hello-world
Unable to find image 'hello-world:latest' locally

#前往dockerhub拉取hello-world镜像
latest: Pulling from library/hello-world
2db29710123e: Pull complete
#镜像基本信息
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
Status: Downloaded newer image for hello-world:latest

#hello-world运行后的提示!
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/

其他命令

6.查看镜像

[root@miaomc-210916 ~] docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 6 months ago 13.3kB

7.卸载Docker

#卸载Docker依赖
yum remove docker-ce docker-ce-cli containerd.io

#删除资源
rm -rf /var/lib/docker
#/var/lib/docker为Docker的默认工作路径有些环境可能配置不一样

8.Docker run流程图

Docker

9.底层原理

Docker是如何工作的?

Docker是一个Client – Server 结构的系统,Docker的守护进程运行在主机上,通过Socket从客户端访问。
DockerServer 接受到 Docker Client 的命令后,就会执行这条命令

docker

【学习笔记】01.Docker
站点链接:https://ali-a.cn/s/notes-01docker
如需转载请标明出处,谢谢您的配合。
暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇