Docker containers: docker basics

Series Article Directory

`

1. Introduction to docker container

1. What is a container

The container runs natively on linux and shares the host's kernel with other containers. It runs an independent process and does not occupy the memory of any other executable files. It is very lightweight.
A virtual machine runs a complete operating system, and virtual access to host resources is performed through a hypervisor, which requires more resources in comparison.

2. Advantages of containers

① Flexible: Even the most complex applications can be containerized.
②Lightweight: The container utilizes and shares the host kernel.
③Interchangeable: Updates and upgrades can be deployed instantly.
④ Portable: Can be built locally, deployed to the cloud, and run anywhere.
⑤Extensible: Container copies can be added and automatically distributed.
⑥Stackable: Services can be stacked vertically and instantly.

3. What is a docker container

Docker is an open source application container engine, developed based on the go language and following the apache2.0 protocol to open source.
Docker is an open source tool for running applications in Linux containers, a lightweight "virtual machine".
Docker's container technology makes it easy to create a lightweight, portable, self-sufficient container for any application on a single host.

4. The logo and design purpose of docker

Docker's logo is designed as a blue whale, dragging many containers.
The whale can be regarded as a host machine, and the container can be understood as a container isolated from each other, and each container contains its own application. Docker's design purpose: Build, Ship and Run Any App, Anywhere,
that is, through the management of the life cycle of application components such as packaging, publishing, deployment, and operation, the purpose of "one-time packaging and running everywhere" at the application component level is achieved. A component here can be an application, a set of services, or even a complete operating system.

5. Comparison between docker and virtual machine

insert image description here

6. Two important technologies of docker container

The essence of docker is a process of the host machine. Docker implements resource isolation through namespace, resource limitation through cgroup, and efficient file operation through copy-on-write technology (similar to virtual machine disks, such as allocating 500g It does not actually take up 500g of physical disk)
insert image description here

7. The three core concepts of docker

①Mirror: a template that includes various environments or services
②Container (container)–object: an instance after the mirror is running is a container, which can be regarded as a simple version of the linux environment
③Warehouse: where the image is saved, divided into Private library and public library The largest public library is the address provided by docker company: hub.docker.com The
three cores and logs of docker are stored under /var/lib/docker by default

2. Docker installation and management

1. Install docker

yum install -y yum-utils device-mapper-persistent-data lvm2
#安装docker的依赖包,yum-utils:提供了 yum-config-manager 工具。
#device mapper: 是Linux内核中支持逻辑卷管理的通用设备映射机制,它为实现用于存储资源管理的块设备驱动提供了一个高度模块化的内核架构。
#evice mapper存储驱动程序需要 device-mapper-persistent-data 和 lvm2。
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#yum源配置为阿里云镜像
yum install -y docker-ce  docker-ce-cli
#安装docker(ce表示社区版,若需安装指定版本则--后跟版本)  

insert image description here

2. Configure the docker accelerator

① Open the official website of Alibaba Cloud and log in to Alibaba Cloud - Welcome to log in to Alibaba Cloud, a safe and stable cloud computing service platform official website to log in.
insert image description here

3. Network optimization

vim /etc/sysctl.conf
net.ipv4.ip_forward=1  #开启路由转发
sysctl -p
systemctl restart network
systemctl restart docke

insert image description here

4. Suggested configuration of the docker-server configuration file

#在daemon. json文件中配置
{
  "graph":"/data/docker",		#数据目录,数据存储位置
  "storage-driver":"overlay2",	#存储引擎,docker1.18以上版本默认使用overlay2存储引擎。早期的适合存储引擎使用的aufs
  "insecure-registries":["registry.access.redhat.com","quary.io"],	#私有仓库
#registry-mirrors 以下添加
  "bip":"172.184.70.1/24",		#docker网络
  "exec-opts":["native.cgroupdriver-systemd"],	#启动时的额外参数,(是一种挂在驱动,k8s使用)
  "live-restore":true	#当docker容器引擎挂掉的时候,使用docker跑起来的容器还能继续运行
}

insert image description here

Summarize

Guess you like

Origin blog.csdn.net/m0_73695023/article/details/131033899