docker

安装 engine

卸载旧版
sudo apt-get purge docker.io*

编辑 /etc/apt/sources.list.d/docker.list

1
echo 'deb https://apt.dockerproject.org/repo debian-jessie main'> /etc/apt/sources.list.d/docker.list

安装依赖: apt-transport-https

1
2
3
sudo apt-get install docker-engine
docker version
...permission问题

创建组

1
2
3
4
 cat /etc/group | grep ^docker  #不存在
sudo groupadd docker #存在忽略,创建组
sudo gpasswd -a ${USER} docker #添加当前用户到组
sudo restart #重启生效

安装 compose

官方文档 https://docs.docker.com/compose/install/#alternative-install-options

Docker Engine

deb package

方法一

curl 安装

1
sudo apt-get install curl

/usr/local/bin 需要权限

1
2
3
4
sudo curl -L "https://github.com/docker/compose/releases/download/1.11.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
.....
curl: (56) SSL read: error:00000000:lib(0):func(0):reason(0), errno 104
网络中断n次,推荐离线

离线下载

1
2
3
sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
方法二

pip安装pip install docker-compose
强烈建议您使用 virtualenv,因为许多操作系统有python系统包与docker-compose依赖关系冲突

国内源

docker search xxxx
error response from daemon: Get https://index.docker.io
被 GFW强了
Docker配置文件/etc/default/docker

1
2
3
4
sudo mousepad /etc/default/docker

#添加 阿里源
DOCKER_OPTS="--registry-mirror=http://mirrors.aliyun.com"

加速地址

1
2
3
4
5
6
7
8
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://自己专属.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

docker-compose.yml

常用配置 安装 compose

卸载

1
2
3
4
5
6
7
8
#docker-engine
sudo apt-get remove docker-engine

# docker-compose
#curl
$ rm /usr/local/bin/docker-compose
# pip
$ pip uninstall docker-compose

docker.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
cat >/usr/lib/systemd/system/docker.service <<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target docker.socket
[Service]
Type=notify
EnvironmentFile=$BASE/flanneld/subnet.env
WorkingDirectory=/usr/local/bin
ExecStart=/usr/bin/dockerd \
\$DOCKER_NETWORK_OPTIONS \
-H unix:///var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

重要概念

Namespace

用来对各种不同的进程上下文进行“障眼法”操作

例如:

Mount Namespace 用于让被隔离进程只看到当前 Namespace 里的挂载点信息

Network Namespace,用于让被隔离进程看到当前 Namespace 里的网络设备和配置

Cgroups

限制一个进程组能够使用的资源上限,包括 CPU、内存、磁盘、网络带宽等等

1
mount -t cgroup

/sys/fs/cgroup/xxx

容器是一个“单进程”模型 由于一个容器的本质就是一个进程,用户的应用进程实际上就是容器里 PID=1 的进程,也是其他后续创建的所有进程的父进程(用 systemd 或者 supervisord 这样的软件来代替应用本身作为容器的启动进程)

proc (lxcfs)

宿主机的 /var/lib/lxcfs/proc/memoinfo 文件挂载到Docker容器的/proc/meminfo位置

images

rootfs(根文件系统)

1
2
$ ls /
bin dev etc home lib lib64 mnt opt proc root run sbin sys tmp usr var

镜像的层都放置在 /var/lib/docker/aufs/diff 目录下

可读可写 rw

read write

修改操作(增、删、改),以增量形式出现在该层,执行docker commit 和 push 指令,保存这个被修改过的可读写层

如,删除文件foo,那么这个删除操作实际上是在可读写层创建了一个名叫.wh.foo 的文件,foo 文件就会被.wh.foo 文件“遮挡”起来,“消失”了

init层 ro+wh

夹在只读层和读写层之间。Init 层是 Docker 项目单独生成的一个内部层,专门用来存放 /etc/hosts、/etc/resolv.conf 等信息。

用户执行 docker commit 只会提交可读写层

只读层 ro+wh

readonly+whiteout

kata

安全容器,旨在提供与传统虚拟化相当的隔离性和安全性,同时保持容器的轻量级和高效性能

https://github.com/kata-containers/kata-containers

docker

/etc/docker/daemon.json文件中配置默认

1
2
3
4
5
6
7
8
{
"runtimes": {
"kata-runtime": {
"path": "/usr/bin/kata-runtime"
}
},
"default-runtime": "kata-runtime"
}

docker info | grep ‘Default Runtime’

containerd

https://github.com/containerd/containerd/blob/main/docs/cri/config.md#runtime-classes

/etc/containerd/config.toml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
version = 2
[plugins."io.containerd.grpc.v1.cri".containerd]
default_runtime_name = "crun"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
# crun: https://github.com/containers/crun
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun]
runtime_type = "io.containerd.runc.v2"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun.options]
BinaryName = "/usr/local/bin/crun"
# gVisor: https://gvisor.dev/
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.gvisor]
runtime_type = "io.containerd.runsc.v1"
# Kata Containers: https://katacontainers.io/
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.kata]
runtime_type = "io.containerd.kata.v2"

检查

1
kata-runtime check

k8s

runtimeClassName指定

1
2
3
4
5
6
7
8
9
10
11
apiVersion: v1
kind: Pod
metadata:
name: kata-pod-demo
spec:
runtimeClassName: kata
containers:
- name: kata-demo
image: kata-runtime/nginx
ports:
- containerPort: 80
点击打赏
文章目录
  1. 1. 安装 engine
  2. 2. 安装 compose
    1. 2.0.1. 方法一
    2. 2.0.2. 方法二
  3. 2.1. 国内源
  4. 2.2. docker-compose.yml
  5. 2.3. 卸载
  • 3. 重要概念
    1. 3.1. Namespace
    2. 3.2. Cgroups
      1. 3.2.1. proc (lxcfs)
    3. 3.3. images
      1. 3.3.1. 可读可写 rw
      2. 3.3.2. init层 ro+wh
      3. 3.3.3. 只读层 ro+wh
  • 4. kata
    1. 4.1. docker
    2. 4.2. containerd
    3. 4.3. k8s
  • 载入天数...载入时分秒... ,