栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Docker 学习笔记-01:安装

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Docker 学习笔记-01:安装

文章目录
  • 安装
    • 前置准备
      • 查看系统及内核版本
      • 卸载旧版本
      • 安装gcc相关
      • 安装yum-utils
      • 设置stable仓库地址(国内镜像源)
      • 更新yum软件包索引
    • 安装启动
      • 安装docker ce
      • 启动docker
      • 查看docker version
      • 运行hello-world
    • 镜像加速
    • 卸载
  • Docker VS Vitual Machine

安装

参考:https://docs.docker.com/engine/install/centos/

前置准备

查看系统及内核版本
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1160.62.1.el7.x86_64 #1 SMP Tue Apr 5 16:57:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

卸载旧版本
sudo yum remove docker 
                  docker-client 
                  docker-client-latest 
                  docker-common 
                  docker-latest 
                  docker-latest-logrotate 
                  docker-logrotate 
                  docker-engine

安装gcc相关
sudo yum -y install gcc
sudo yum -y install gcc-c++

安装yum-utils
sudo yum install -y yum-utils

设置stable仓库地址(国内镜像源)
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

更新yum软件包索引
sudo yum makecache fast

安装启动

安装docker ce
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

启动docker
sudo systemctl start docker

查看docker version
[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.14
 API version:       1.41
 Go version:        go1.16.15
 Git commit:        a224086
 Built:             Thu Mar 24 01:49:57 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.14
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       87a90dc
  Built:            Thu Mar 24 01:48:24 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.11
  GitCommit:        3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc:
  Version:          1.0.3
  GitCommit:        v1.0.3-0-gf46b6ba
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

运行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
2db29710123e: Pull complete 
Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67
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/

镜像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://mk9i2p1z.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

卸载
systemctl stop docker
yum remove docker-ce docker-ce-cli containerd.io
rm -rf /var/lib/docker
rm -rf /var/lib/containerd

Docker VS Vitual Machine
  • docker 有着比虚拟机更少的抽象层:由于docker不需要虚拟机实现硬件资源虚拟化,运行在docker容器上的程序直接使用的是宿主机的硬件资源,在资源利用率上有明显优势
  • docker 利用宿主机的内核,无需加载OS内核:当新建一个 docker 容器时,不需要和虚拟机一样重新加载一个操作系统内核,进而避免引导、网络配置、系统相关库资源的过程,在创建过程耗时上也是具备明显优势

Docker容器虚拟机(VM)
操作系统与宿主机共享OS宿主机OS上运行这虚拟机OS
存储大小镜像小,便于存储和运输镜像庞大(vmdk、vdi)
运行性能几乎无额外性能损失操作系统额外的CPU、内存消耗
移植性轻便、灵活笨重、与虚拟化技术耦合度高
亲和性面向软件开发者面向硬件运维者
部署速度秒级较慢

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/945293.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号