### 寫在前面
之前寫過一篇關于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文件