Docker系列(1) 基本配置

2 阅读5分钟

1、什么是docker?

当人们说“Docker”时,他们通常是指 Docker Engine,它是一个客户端 - 服务器应用程序,由 Docker守护进程、一个REST API指定与守护进程交互的接口、和一个命令行接口(CLI)与守护进程通信(通过封装REST API)。Docker Engine 从 CLI 中接受docker 命令,例如 docker run 、docker ps 来列出正在运行的容器、docker images 来列出镜像,等等。

  • docker是一个软件,可以运行在window、linux、mac等各种操作系统上
  • docker 是一个开源的应用容器引擎,基于Go 语言开发并遵从 Apache2.0 协议开源,项目代码托管在github上进行维护
  • docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上
  • 容器是完全使用沙箱机制,相互之间不会有任何接口,更重要的是容器性能开销极低

2、docker基本组成

  • docker主机(Host):安装了Docker程序的机器(Docker直接安装在操作系统之上)
  • docker仓库(Registry):用来保存各种打包好的软件镜像;仓库分为公有仓库和私有仓库。(很类似maven)
  • docker镜像(Images):软件打包好的镜像;放在docker仓库中
  • docker容器(Container):镜像启动后的实例称为一个容器;容器是独立运行的一个或一组应用

3、docker与操作系统比较

docker是一种轻量级的虚拟化方式。与传统操作系统技术的特性比较如下表

特性容器虚拟机
启动速度秒级分钟级
性能接近原生较弱
内存代价很小较多
硬盘使用一般为MB一般为GB
运行密度单机支持上千个容器一般几十个
隔离性安全隔离完全隔离
迁移性优秀一般

传统的虚拟机方式提供的是相对封闭的隔离。Docker利用Linux系统上的多种防护技术实现了严格的隔离可靠性,并且可以整合众多安全工具。从 1.3.0版本开始,docker重点改善了容器的安全控制和镜像的安全机制, 极大提高了使用docker的安全性。

4、安装docker前置条件

节点信息

在本系列中,建立一个单机实例进行测试 服务器用户名:root,服务器密码:root

主机名IP地址说明
docker-100192.168.1.100docker主机

centos 配置

centos下载版本号:CentOS-7-x86_64-Minimal-2003.iso

http://mirrors.aliyun.com/centos/7/isos/x86_64/

查看centos系统版本命令

[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)

配置阿里云yum源

1.下载安装wget
yum install -y wget

2.备份默认的yum
mv /etc/yum.repos.d /etc/yum.repos.d.backup

3.设置新的yum目录
mkdir -p /etc/yum.repos.d

4.下载阿里yum配置到该目录中,选择对应版本
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

5.更新epel源为阿里云epel源
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

6.重建缓存
yum clean all
yum makecache

7.看一下yum仓库有多少包
yum repolist

升级系统内核

rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

yum --enablerepo=elrepo-kernel install -y kernel-lt

grep initrd16 /boot/grub2/grub.cfg

grub2-set-default 0

reboot

常用查询命令

  • 查看centos系统内核命令
[root@localhost ~]# uname -r
5.4.193-1.el7.elrepo.x86_64

[root@localhost ~]# uname -a
Linux localhost.localdomain 5.4.193-1.el7.elrepo.x86_64 #1 SMP Tue May 10 17:06:01 EDT 2022 x86_64 x86_64 x86_64 GNU/Linux
  • 查看CPU命令
[root@localhost ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    1
Core(s) per socket:    2
Socket(s):             2
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 62
Model name:            Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz
  • 查看内存命令
[root@localhost ~]# free
              total        used        free      shared  buff/cache   available
Mem:        3904100      727696     1987932        9472     1188472     2937124
Swap:       2097148           0     2097148

[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G        710M        1.9G        9.2M        1.1G        2.8G
Swap:          2.0G          0B        2.0G
  • 查看硬盘信息
[root@localhost ~]# fdisk -l

Disk /dev/sda: 59.1 GB, 59055800320 bytes, 115343360 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d369e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   115343359    56622080   8e  Linux LVM

Disk /dev/mapper/centos-root: 37.5 GB, 37513854976 bytes, 73269248 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 18.3 GB, 18312331264 bytes, 35766272 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

  • 关闭防火墙
systemctl stop firewalld

systemctl disable firewalld
  • 命令补全
安装bash-completion
yum -y install bash-completion bash-completion-extras

使用bash-completion
source /etc/profile.d/bash_completion.sh
  • 上传文件
yum -y install lrzsz

1.鼠标拖拽上传文件
2.下载文件
    2.1 下载一个文件
    sz filename

    2.2 下载多个文件
    sz filename1 filename2

    2.3 下载dir目录下所有文件,不包含dir下的文件夹
    sz dir/*