### 写在前面
之前写过一篇关于docker安装的博客,那种方式安装有很多缺点。运行docker和使用docker的时候会产生多个进程,占用Linux主机的资源。于是,我找到了新的方式安装docker。
### 重要的三个文件
```bash
/usr/lib/systemd/system/docker.service
/usr/lib/systemd/system/docker.socket
/usr/lib/systemd/system/containerd.service
```
## 开始安装docker
### 添加docker用户
```bash
groupadd docker
```
### 下载docker
```bash
https://download.docker.com/linux/static/stable/x86_64/docker-20.10.7.tgz
```
### 解压
```bash
tar xzvf docker-20.10.7.tgz
```
### 复制文件到/usr/bin/ 目录下
```bash
cp docker/* /usr/bin/
```
`建议把docker文件复制到/usr/bin/目录下,如果移动到别的目录有点问题,systemctl脚本启动不起来。`
### 创建docker.socket文件
```bash
cat > /usr/lib/systemd/system/docker.socket << 'EOF'
[Unit]
Description=Docker Socket for the API
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
EOF
```
### 创建containerd.service文件
```bash
cat > /usr/lib/systemd/system/containerd.service << 'EOF'
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=1048576
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
EOF
```
### 创建docker.server文件
```bash
tee /usr/lib/systemd/system/docker.service <<-'EOF'
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --graph=/data/docker -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# 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
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# 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
OOMScoreAdjust=-500
[Install]
WantedBy=multi-user.target
EOF
```
`启动重要的参数:/usr/bin/dockerd --graph=/data/docker -H fd:// --containerd=/run/containerd/containerd.sock`
### 启动docker容器
```bash
#重新加载配置文件
systemctl daemon-reload
#启动
systemctl start docker
#设置开机启动
systemctl enable docker.service
#查看docker服务状态
systemctl status docker
#查看docker版本
docker -v
#查看docker容器里的镜像
docker images
#查看容器数据文件存储路径
docker info |grep "Docker Root"
```
### 镜像导入
```bash
[root@ncayu docker-images]# docker load -i minio-latest.tar
[root@ncayu docker-images]# docker load -i mysql-5.7.tar
[root@ncayu docker-images]# docker load -i redis-6.2.3.tar
```
### docker进程展示
## 安装docker-compose1.25.0
```bash
curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
# 添加快捷启动连接
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
# 测试安装结果
docker-compose --version
```
- 写在前面
- linux命令行
- 基础篇
- 1.SSH连接工具
- 2.查看系统版本信息
- 3.查看IP地址
- 4.查看cpu信息
- 5.查看内存磁盘信息
- 6.文件上传下载
- 7.linux中查找文件(find)
- 8.修改root账号密码
- 9.通过进程号查看端口
- 10.校验MD5值
- 11.Linux命令之seq
- 12.Linux命令之corntab
- 13.linux命令之awk
- 进阶篇
- 查看防火墙是否开启
- linux创建新的用户
- 更改文件的用户组
- 查找JAVA_HOME路径
- Linux主机时间同步
- 高CPU排查-个人总结
- Linux查看GPU性能
- 文件排序工具sort
- sed
- grep
- 实战篇
- 1.Linux基线
- 2.iptables学习
- 3.Tcpdump抓包命令
- 4.CentOS7更换镜像源
- shell脚本篇
- 1.Shell脚本速查手册
- 2.Shell中获取取昨天和多天前日期
- 3.rsync删除文件
- 4.nginx自动化安装脚本
- 5.后台启动服务
- 6.备份文件保留5天
- 数据库
- MySQL数据库备份命令
- ES数据库备份
- filebeat工具
- packetbeat工具
- MySQL数据库中删除表
- Docker容器
- 1.安装docker容器
- 2.docker容器的使用
- 3.docker overlay2 是存放什么的
- 4.docker删除已停止的容器
- 5.docker网卡的IP地址修改
- Ubuntu容器下载vim,curl命令
- docker磁盘占用瞬间变大问题解决
- Python学习
- 安装python环境
- Python 把代码编译成pyc文件